Python爬虫包 BeautifulSoup的各种html解析器的比较及使用

BeautifulSoup号称Python中最受欢迎的HTML解析库之一,但是这并不是唯一的选择。

BeautifulSoup(markup,"html.parser")

优点

python自身带有 
速度比较快 
能较好兼容 (as of Python 2.7.3 and 3.2.)

缺点

不能很好地兼容(before Python 2.7.3 or 3.2.2)

BeautifulSoup(markup,"lxml")

优点

速度很快 
兼容性好

缺点

需要额外的C语言支持

BeautifulSoup(markup, "lxml-xml") BeautifulSoup(markup,"xml")

优点

速度很快

缺点

现在只支持xml解析 
需要额外的C语言支持

BeautifulSoup(markup, "html5lib")

优点

兼容性很好 
可以像web浏览器一样解析html页面 
Creates valid HTML5

缺点

速度很慢 
需要额外的python支持




猜你喜欢

转载自blog.csdn.net/jenrey/article/details/81010442
今日推荐