六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 92|回复: 0

BeautifulSoup 解析html <script>标签的问题

[复制链接]

升级  64%

40

主题

40

主题

40

主题

秀才

Rank: 2

积分
146
 楼主| 发表于 2013-2-7 18:23:42 | 显示全部楼层 |阅读模式
美丽的汤BeautifulSoup是python下非常好用的html解析器
但是新版本的BeautifulSoup 3.1.0解析 html <script>标签有问题,会报HTMLParseError: malformed start tag的异常
这个作者也是承认的
 
他给出了几个解决办法:

1. You can pretend that Beautiful Soup version 3.1.0 was never released. Version 3.0.7a still works fine on Python 2.3 through 2.6.
2. You can use html5lib. That library has a Beautiful Soup tree builder that will yield standard Beautiful Soup objects. It depends on Beautiful Soup to run.
3. You can use ElementTree. If you want the Beautiful Soup API, you can use Element Soup to feed the HTML into Beautiful Soup once ElementTree has cleaned it up.
4. You can use lxml. It doesn't have all of Beautiful Soup's tree-traversal methods, but it's a fast and easy-to-use parser.
5. You can do some of the work yourself, and send me the result. 3.1.0 includes the start of the refactoring work for making the parser pluggable, moving HTMLParser code into a parser class.
 
最简单的就是第一条 更换老版本3.0.7a,一切正常
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表