Parsing HTML in Python [closed]

2019-01-02 16:00发布

What's my best bet for parsing HTML if I can't use BeautifulSoup or lxml? I've got some code that uses SGMLlib but it's a bit low-level and it's now deprecated.

I would prefer if it could stomache a bit of malformed HTML although I'm pretty sure most of the input will be pretty clean.

6条回答
妖精总统
2楼-- · 2019-01-02 16:09

You can install lxml and many other python modules easily and seamlessly on the Mac (OS X) using Pallet, which is the MacPorts official GUI

The module name is py27-lxml. Easy as 1,2,3.

查看更多
查无此人
3楼-- · 2019-01-02 16:26

html5lib is good:
http://code.google.com/p/html5lib/

Update: The link above is broken. A third-party mirror of above, can be accessed from https://github.com/html5lib/gcode-import

查看更多
浮光初槿花落
4楼-- · 2019-01-02 16:27

http://www.xmlhack.com/read.php?item=1392 http://sourceforge.net/projects/pirxx/

http://pyxml.sourceforge.net/topics/

I don't have much experience with python, but I have used Xerces (from the Apache foundation) in the past and found it to be very useful. The learning curve isn't bad either, though I'm not coming from a python perspective. I suggest you consider it though. (The first two links I've included discuss python interfaces to Xerces and the last one is the first google hit on "python xml").

查看更多
临风纵饮
5楼-- · 2019-01-02 16:27

htql is good at handling malformed html:

http://htql.net/

查看更多
怪性笑人.
6楼-- · 2019-01-02 16:28

Perhaps µTidylib will meet your needs?

查看更多
若你有天会懂
7楼-- · 2019-01-02 16:32

Python has a native HTML parser, however the Tidy wrapper Nick suggested would probably be a solid choice as well. Tidy is a very common library, (written in C is it?)

查看更多
登录 后发表回答