几个在python下用于处理模板文件或解析html页面的工具集合,也即所谓的“Screen Scraping”。比用python 基础包的robotparser及htmlparser方便多了,也比直接用正则表达式效率高多了。一般而言,对于html页面的解析(搜索引擎的spider必须要做的事情)应该有如下几种方式处理:
1、正则表达式。
2、如果文件为xhtml的话(如果为普通html,可以借助诸如tidy转化为xhtml),对xhtml直接用xpath解析。
3、借助xml解析器对xhtml页面按照dom树或sax方式进行解析
- BeautifulSoup
http://www.crummy.com/software/BeautifulSoup/
- templatemaker
http://www.holovaty.com/blog/archive/2007/07/06/0128
- webstemmer
http://www.unixuser.org/~euske/python/webstemmer/
-
twill(基于BeautifulSoup)
- Perl版本的工具
http://search.cpan.org/dist/Template-Extract/
http://search.cpan.org/~petdance/WWW-Mechanize/
http://search.cpan.org/dist/FEAR-API/
- Ruby版本的工具
http://code.whytheluckystiff.net/hpricot/ 基于HTree和JQuery
- Java版本的工具
HTML Screen Scraping Tools Written in Java
好像没有提到http://htmlparser.sourceforge.net/,挺方便的。
PS .发现两个不错的服务,有空研究一下:
- 自定义API的工具dapper:
http://www.dapper.net/,有空研究一下怎样利用以上工具实现
- MIT的个人信息门户piggy-bank及Solvent
以前看过,基于firefox插件的,piggy-bank的思路很值得借鉴,尤其是做个人门户。
http://simile.mit.edu/wiki/Solvent
http://simile.mit.edu/piggy-bank/