概述
编码后的html:
def getHtml(self,url):
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0",
"Connection":"keep-alive",
}
r = requests.get(url,headers=headers)
html = r.text.encode(r.encoding)
return html
执行
bs = BeautifulSoup(html)
结果报错如下;
encoding error : input conversion failed due to input error, bytes 0xAC 0xE5 0x8F 0xB8
Unicode的hmtl:
def getHtml(self,url):
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0",
"Connection":"keep-alive",
}
r = requests.get(url,headers=headers)
html = r.text
return html
执行
bs = BeautifulSoup(html)
结果报错如下;
encoding error : input conversion failed due to input error, bytes 0xA1 0x6C 0x09 0x67
玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/wenda/wd19041.html
相关文章 Recommend
最后
以上就是魁梧老虎为你收集整理的python encoding报错_Python BeautifulSoup报错encoding error问题的全部内容,希望文章能够帮你解决python encoding报错_Python BeautifulSoup报错encoding error问题所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复