首页 > 编程 > Python > 正文

解决python3爬虫无法显示中文的问题

2019-11-25 14:56:29
字体:
来源:转载
供稿:网友

有时候使用python从网站上爬数据的时候,如果数据里包含中文,有时候显示的却是如下所示.../xe4/xba/xba/xef/xbc/x8c/xe6...类似与国际化

解决方法:

import urllib.requestimport sysweburl="..."webhead=...req=urllib.request.Request(url=weburl,headers=webhead)response=urllib.request.urlopen(req)content = response.read()#获得系统的编码type = sys.getfilesystemencoding()#设置爬出内容的编码content = content.decode(type)file = open("c。txt",'w',10000)file.write(str(content))file.close()print(content)

以上这篇解决python3爬虫无法显示中文的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表