2011-05-03 56 views

回答

8

內置的HTMLParser模塊: http://docs.python.org/py3k/library/html.parser.html

不是本地人,但值得一提的; BeautifulSoup: http://www.crummy.com/software/BeautifulSoup/

+0

+1爲美麗的湯,因爲現實世界的HTML是friggin的混亂。 BS只是隨着你拋出的任何垃圾滾動,並微笑起來。 – 2011-05-03 19:46:09

+0

@Peter:不幸的是,BeautifulSoup在Python 3中效果不好,因爲它依賴於sgmllib。我弄亂了它使用新的html5lib,但它不完整。 https://code.launchpad.net/~takowl/beautifulsoup/3k http://code.google.com/r/takowl-html5lib/(如果您有興趣,請隨時加以處理)。 – 2011-05-03 20:00:58

+0

完美。我想我會使用HTMLParser,因爲它與'sgmllib'非常相似。我也讀了很多關於'BeautifulSoup'的文章,大家都在抱怨Python 3的兼容性問題。謝謝。 – David 2011-05-03 20:03:35

3

不知道你的母語是什麼意思,但我的lxml忠實粉絲。

+0

+1我發現lxml比BeautifulSoup更好 – ilprincipe 2011-05-08 20:19:34

+0

+1第二次ilprincipe,lxml更好:更靈活,更快。尤其是與Twisted一起使用時。 – ARF 2011-06-27 17:01:09