2024-09-28 05:25:12 发布
网友
我正在编写一个简单的脚本来从here获取大的灰色表。在
我的代码如下:
import urllib2 from lxml import etree html = urllib2.urlopen("http://www.afi.com/100years/movies10.aspx").read() root = etree.XML(html)
但是我得到了一个关于最后一个陈述的错误。在
你知道我怎样才能避免这个错误吗?在
谢谢。在
您尝试用XML解析器解析HTML,应该使用lxml HTML解析器。在
import urllib2 from StringIO import StringIO from lxml import etree ufile = urllib2.urlopen("http://www.afi.com/100years/movies10.aspx") root = etree.parse(ufile, etree.HTMLParser()) print etree.tostring(root)
链接到的文档不是格式正确的XHTML,因此不能使用XML解析器来加载它。在
您必须使用类似Beautiful Soup的HTML解析器。在
您尝试用XML解析器解析HTML,应该使用lxml HTML解析器。在
链接到的文档不是格式正确的XHTML,因此不能使用XML解析器来加载它。在
您必须使用类似Beautiful Soup的HTML解析器。在
相关问题 更多 >
编程相关推荐