1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Python解决爬虫中文返回乱码问题

Python解决爬虫中文返回乱码问题

时间:2023-10-03 01:03:45

相关推荐

Python解决爬虫中文返回乱码问题

ISO-9959-1的问题

直接上干货

import reimport requestsnew_url = "http://www.anquan.us/static/drops/papers-17213.html"res = requests.get(url=new_url).content.decode('utf-8')print (res)"""if res.encoding == 'ISO-8859-1':encodings = requests.utils.get_encodings_from_content(res.text)if encodings:encoding = encodings[0]else:encoding = res.apparent_encodingelse:encoding = res.encodingencode_content = res.content.decode(encoding, 'replace').encode('utf-8', 'replace').decode('utf-8')"""#print(encode_content)#print(res.encoding)#print(res.apparent_encoding)#print(requests.utils.get_encodings_from_content(res.text))

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。