Issue parsing a xhtml page using Python

时光毁灭记忆、已成空白 提交于 2019-12-04 17:21:17

The problem is expat is using fb as the namespace prefix, but that tag is FB:LOGIN-BUTTON. Expat sees FB as unbound. The XHTML specification notes that all HTML elements and attributes must be lowercase since XML is case-sensitive.

I tried your document using the lxml XML parser and it auto-converted the prefixes to lowercase. Perhaps you can switch to a different parser:

import lxml.etree
data = open('fb.xhtml', 'rb').read()
tree = lxml.etree.fromstring(data)
ns_map = {'fb': 'http://www.facebook.com/2008/fbml'}
print tree.xpath('.//fb:LOGIN-BUTTON', namespaces=ns_map)

Output:

[<Element {http://www.facebook.com/2008/fbml}LOGIN-BUTTON at 1011fa260>]

I think the problem is that http://www.facebook.com/2008/fbml is a not found page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!