---
title: "python解析HTML的工具总结"
author: "john2007"
date: "2010-10-04T11:24:11Z"
tags: []
categories: ["编程语言"]
slug: "python-html"
draft: false
lastmod: "2010-10-04T11:25:57Z"
id: 777087
url: "https://john2007.iteye.com/blog/777087"
---

做HTML解析工作也有好多次了，每次总是面临着选择不同工具的困惑。刚刚开始时正则表达式，之后用beautifulsoup,还用过python自带的htmlparser,sgmlparser。在前几篇博客中还提到了其自身的一些bug.

 [http://john2007.iteye.com/blog/559840](http://john2007.iteye.com/blog/559840)

做数据提取的时候，越来越感觉到美丽的汤功能的有限，最终还是选择了Xpath。在用xpath做HTML解析的库，也是比较多的。

 

现在回首总结一下，推荐用lxml, elementtree，libxml2.

Both [lxml](http://codespeak.net/lxml/) and Scrapy Selectors are built over the [libxml2](http://xmlsoft.org/) library.

 

不知各位同仁还有什么好的工具交流一下。在下就抛砖引玉，静候佳音了。![](/images/smiles/icon_arrow.gif)