request = urllib2.Request(url,headers = headers)
response = urllib2.urlopen(request)
response = urllib2.urlopen(request)
content = response.read()
soup = BeautifulSoup(content,'html.parser',from_encoding='utf-8')node = soup.find_all('div',class_="article block untagged mb15")
print node
抓取页面的编码是utf-8,但使用find_all()方法输出node后就会产生乱码:
解决办法
这里FindALL是一个list,要输应该循环输出
for _ in FindALL:
print _.encode('utf-8')
本文介绍了一种常见的网页爬虫中遇到的乱码问题及其解决方案。通过使用正确的编码方式,可以有效避免爬取内容出现乱码的情况。具体方法是在输出时指定正确的字符编码。
2768

被折叠的 条评论
为什么被折叠?



