Python3.5解析网页汉字都是乱码解决方法

Posted ydqq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python3.5解析网页汉字都是乱码解决方法相关的知识,希望对你有一定的参考价值。

python3.5解析网页之后,汉字成了乱码,解决方法如下:

#加上一个编码方法
html.encoding = html.apparent_encoding

例:

import requests
from bs4 import BeautifulSoup

html = requests.get('http://www.baidu.com')
html.encoding = html.apperent_encoding
soup = BeautifulSoup(html.text, 'lxml')

以上是关于Python3.5解析网页汉字都是乱码解决方法的主要内容,如果未能解决你的问题,请参考以下文章