python大佬请进,关于抓取的数据格式的问题

查看 57|回复 2
作者:张大牛   
最近百度上线的chat  https://chat.baidu.com/
想自己套个壳玩玩,原打算是用PHP的,但是因为这个结果是流数据,PHP的curl貌似搞不定,只好转到python
代码已完成90%
baidu.rar
代码运行成功,也有返回数据
但返回的数据都是这种格式
C:\>python baidu.py
请求成功
event:ping
event:message
data:{"status":0,"qid":"12643291455431891488","pkgId":"cd971053-9663-4d88-8a54-2
c428ddbf3b7_0","sessionId":"43d95fc2-b94f-442f-9c5b-b8078f712862","isDefault":1,
"isShow":0,"data":{"message":{"msgId":"cd971053-9663-4d88-8a54-2c428ddbf3b7","is
Rebuild":false,"updateTime":"1694966929746","metaData":{"state":"waiting-resp","
endTurn":false,"userInfo":{"status":3}},"content":{}}}}
event:message
data:{"status":0,"qid":"12643291455431891488","pkgId":"cd971053-9663-4d88-8a54-2
c428ddbf3b7_1","sessionId":"43d95fc2-b94f-442f-9c5b-b8078f712862","isDefault":1,
"isShow":0,"data":{"message":{"msgId":"cd971053-9663-4d88-8a54-2c428ddbf3b7","is
Rebuild":false,"updateTime":"1694966933900","metaData":{"state":"waiting-resp","
endTurn":false,"userInfo":{"status":3}},"content":{"searchQuery":{"querys":["鲁
迅是谁"]}}}}}
event:message
data:{"status":0,"qid":"12643291455431891488","pkgId":"cd971053-9663-4d88-8a54-2
c428ddbf3b7_2","sessionId":"43d95fc2-b94f-442f-9c5b-b8078f712862","isDefault":1,
"isShow":0,"data":{"message":{"msgId":"cd971053-9663-4d88-8a54-2c428ddbf3b7","is
Rebuild":false,"updateTime":"1694966933978","metaData":{"state":"generating-resp
","endTurn":false,"userInfo":{"status":3}},"content":{"generator":{"text":"鲁迅
,原名周樟","type":"txt","showType":"append","antiFlag":0,"isFinished":false}}}}
}
event:message
data:{"status":0,"qid":"12643291455431891488","pkgId":"cd971053-9663-4d88-8a54-2
c428ddbf3b7_3","sessionId":"43d95fc2-b94f-442f-9c5b-b8078f712862","isDefault":1,
"isShow":0,"data":{"message":{"msgId":"cd971053-9663-4d88-8a54-2c428ddbf3b7","is
Rebuild":false,"updateTime":"1694966934570","metaData":{"state":"generating-resp
","endTurn":false,"userInfo":{"status":3}},"content":{"generator":{"text":"寿,
后改名周树人,字豫山,后改字豫才,是浙江绍兴的人。","type":"txt","showType":"app
end","antiFlag":0,"isFinished":false}}}}}
请问怎么才能把需要的text内容提取出来,组成完整的答案?
求大佬指教

大佬, 鲁迅, 数据

taiyi747   
正则万能,你这个格式我前两天刚处理过,把内容交给ai让他给你写正则表达式就好了
BackDoor   
python 有  json库直接输出的。
您需要登录后才可以回帖 登录 | 立即注册

返回顶部