python如何抓取类型为EventStream的数据
python如何抓取类型为EventStream类型的数据,如下图
直接requests.get会一直等待获取不到内容。
python如何抓取类型为EventStream的数据
python如何抓取类型为EventStream类型的数据,如下图
使用stream参数和iter_content方法
s=""
resp=requests.get(url,stream=True)
print(resp.headers)
for chunk in resp.iter_content(chunk_size=1024):
text=chunk.decode('utf-8')
s+=text.strip('\n')
if text.endswith('\n\n'):##第一条发送读取完毕,关闭链接退出
resp.close()
break