Чтобы не забыть всю эту лабуду и гребаные стандарты:
http://lxml.de/tutorial.html
http://code.google.com/p/html5lib/wiki/UserDocumentation
http://habrahabr.ru/blogs/python/114788/
http://python.su/forum/viewtopic.php?id=8188
http://ru.wikipedia.org/wiki/XPath
http://code.google.com/p/py-dom-xpath/
И что-то типо этого:
code:
parser = html5lib.HTMLParser(tree=treebuilders.getTreeBuilder("lxml"))
doc_tree = parser.parse(StringIO.StringIO(html_text))
#print etree.tostring(doc_tree)
find_img = etree.XPath(".//html:img", namespaces={"html":"http://www.w3.org/1999/xhtml"})
for node in find_img(doc_tree):
print node.get("src")
print "*"*80
find_idkey = etree.XPath(".//html:input", namespaces={"html":"http://www.w3.org/1999/xhtml"})
for node in find_idkey(doc_tree):
print node.get("name") + " == " + node.get("value")