无法使用PyQuery解析大HTML

时间:2013-05-13 15:49:56

标签: python python-2.7 pyquery

由于我不确定我所遇到的问题是否是我身边的错误或缺乏知识,我想请你帮忙。

案例是,当尝试使用PyQuery解析此URL(http://ies.ieee-ies.org/resources/media/publications/TIEpub/1988_2013.htm)时,显然它仅加载标题,并忽略正文:

>>> import urllib2
>>> from pyquery import PyQuery as pq

>>> response = urllib2.urlopen('http://ies.ieee-ies.org/resources/media/publications/TIEpub/1988_2013.htm').read() # 9MB page
>>> len(response)
9835026
>>> dom = pq(response)
>>> dom.html()
u'<head><title>IEEE Transactions on Industrial Electronics</title></head><body><h1 align="center">&#13;\n   <img border="0" src="ieeelogo.gif"/><font color="#FF6600">\xa0IEEE Tr
ansactions on Industrial Electronics\xa0&#13;\n   <img border="0" src="ieslogo.gif"/></font>&#13;\n   </h1><h2 align="center">&#13;\n   Volume 35, \xa0Number 1, Feb 1988 \xa0\xa
0\xa0\xa0\xa0\xa0\xa0\xa0\xa0&#13;\n   <a href="http://ieeexplore.ieee.org/xpl/RecentIssue.jsp?punumber=41"><font size="4">Access to the journal on IEEE XPLORE</font></a><font s
ize="4"> </font>\xa0\xa0\xa0&#13;\n   <a href="http://tie.ieee-ies.org/"><font size="3">IE Transactions Home Page</font></a><font size="4"> </font> &#13;\n   </h2><hr/><br/><br/
></body>'

我不知道PyQuery上的HTML解析是否有大小限制?

PS:我有一个使用不同页面的工作导致相同的内容,但我想知道这是什么原因。

1 个答案:

答案 0 :(得分:2)

我很确定问题不是大小,而是这个页面的HTML非常破碎。例如,它有超过2000 <html>个标签(正确的数字是 1)。我很震惊浏览器可以对它有任何意义,但是Mozilla开发者我有很多这方面的经验,我想PyQuery开发者虽然无疑是勤奋的,但可能要少得多。如果您可以从其他页面获取内容,那么请务必这样做,特别是如果该页面不那么破碎。