HTMLParser错误解决

来源:互联网 发布:淘宝的体检中心在哪里 编辑:程序博客网 时间:2024/06/05 05:30

费劲巴拉写了一个爬虫程序,总算运行顺利了,结果有出现了一个HTMLParser错误,

提示信息如下:

HTMLParser.HTMLParseError: malformed start tag

提示内容大概是说,这个不是BS的bug,如果需要解决,需要使用一个新的网页解析器lxml或者html5lib.

好吧,安装html5lib或者lxml。

lxml: lxml由于GCC版本的问题一直显示安装失败.

html5lib安装成功后,import时候又出现错误:

>>> import html5lib

Traceback (most recent call last):

  File "<stdin>",line 1, in <module>

  File"/usr/local/lib/python2.6/dist-packages/html5lib/__init__.py", line16, in <module>

    from .html5parserimport HTMLParser, parse, parseFragment

  File"/usr/local/lib/python2.6/dist-packages/html5lib/html5parser.py",line 9, in <module>

    from ordereddictimport OrderedDict

ImportError: No module named ordereddict

网上查了一下,需要再安装一个ordereddict

http://www.cnblogs.com/xiami303/archive/2012/08/28/2660657.html

作者说:后来我知道,其实可以easy_install安装OrderedDictpackage


安装成功后改了一下脚本内容:

加上:import html5lib

原:soup = BeautifulSoup(html,'html.parser')

现:soup = BeautifulSoup(html,'html5lib')

再试一下出问题的网页,成功了~~~

撒花,感谢~~~~~~~~~~~~~~~~~~~~