我是靠谱客的博主 魁梧老虎,这篇文章主要介绍python encoding报错_Python BeautifulSoup报错encoding error问题,现在分享给大家,希望可以做个参考。

编码后的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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(125)

评论列表共有 0 条评论

立即
投稿
返回
顶部