完美解决python 爬虫 中文 乱码
程序员文章站
2022-05-28 13:02:50
...
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
}
req = requests.get(url,headers=headers)
# 如果设置为replace,则会用?取代非法字符,''也可
print(req.content.decode('gbk','replace'))