BeautifulSoup 解析html <script>标签的问题
美丽的汤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,一切正常
页:
[1]