马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
在测试知乎回答采集的时候发现中文乱码,请问是什么原因造成的?有什么办法解决吗?
这是在Jason的文字:
json的文字
这是代码输出的文字:
输出文字
源代码:import json
import requests
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36'}
url = "https://www.zhihu.com/api/v4/questions/310681355/answers?include=data%5B%2A%5D.is_normal%2Cadmin_closed_comment%2Creward_info%2Cis_collapsed%2Cannotation_action%2Cannotation_detail%2Ccollapse_reason%2Cis_sticky%2Ccollapsed_by%2Csuggest_edit%2Ccomment_count%2Ccan_comment%2Ccontent%2Ceditable_content%2Cvoteup_count%2Creshipment_settings%2Ccomment_permission%2Ccreated_time%2Cupdated_time%2Creview_info%2Crelevant_info%2Cquestion%2Cexcerpt%2Crelationship.is_authorized%2Cis_author%2Cvoting%2Cis_thanked%2Cis_nothelp%2Cis_labeled%2Cis_recognized%2Cpaid_info%2Cpaid_info_content%3Bdata%5B%2A%5D.mark_infos%5B%2A%5D.url%3Bdata%5B%2A%5D.author.follower_count%2Cbadge%5B%2A%5D.topics&limit=5&offset=0&platform=desktop&sort_by=default"
req = requests.get(url,headers = headers)
target = json.loads(req.text)['data'][1]['excerpt']
print(target)
本帖最后由 快速收敛 于 2019-8-29 18:07 编辑
字的编码问题, target = json.loads(req.content.decode("utf-8"))['data'][1]['excerpt']
网页可能不是utf-8编码,直接获取二进制源码,再转化成utf-8编码
|