junjie 通过本文主要向大家介绍了python beautifulsoup,python beautiful,beautiful4包python,beautifulsoup,beautifulsoup安装等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
在用BeautifulSoup进行抓取页面的时候,会各种各样的编码错误。
可以通过在beautifulsoup中指定字符编码,解决问题。
import urllib2
from BeautifulSoup import BeautifulSoup
page = urllib2.urlopen('http://www.163.com');
soup = BeautifulSoup(page,from_encoding="gb2312")
print soup.originalEncoding
print soup.prettify()
</div>
红色部分表示需要注意的地方。在BeautifulSoup构造器中传入fromEncoding参数即可解决乱码问题,当然具体参数值是什么就要看你获取页面的编码是什么
您可能想查找下面的文章:
- Python利用Beautiful Soup模块创建对象详解
- Python利用Beautiful Soup模块修改内容方法示例
- Python利用Beautiful Soup模块搜索内容详解
- Python利用Beautiful Soup模块创建对象详解
- Python利用Beautiful Soup模块修改内容方法示例
- Python使用BeautifulSoup库解析HTML基本使用教程
- python基于BeautifulSoup实现抓取网页指定内容的方法
- Python中使用Beautiful Soup库的超详细教程
- Python中使用Beautiful Soup库的超详细教程
- python使用BeautifulSoup分页网页中超链接的方法

