逐行处理下载文件stream=True与iter_lines()

data5 = {
“key’:key,
}
print(“data5:”,data5) s = requests.session() r5 = s.get(url=try_download_url, params=data5,allow_redirects=False) print(“r5 positionfile:”,r5.headers[“positionfile”])
location_url= r5.headers[“positionfile”]
r6 = s.get(location_url,stream=True,timeout=300)
i =0
print(“r6:”,r6.status_code)
for line in r6.iter_lines():
print(“i:”,i)
if i>5:break
print(“line:”,line)
print(“type:”,type(line))
print(chardet.detect(line))
print(line.decode(‘GB2312’))
i+=1

你可能感兴趣的:(笔记)