我正在尝试从html文件中获取数据。我使用的代码似乎可以正常工作,但并不像我预期的那样。我可以得到一些项目,但不是全部,我想知道这是否与我试图读取的文件的大小有关。在
我正在尝试解析this webpage的源代码。在
这页有4500行长,所以它是一个相当好的大小。我一直在使用这个页面,因为我想确保代码在大文件上工作。在
我使用的代码是:
import lxml.html
import lxml
import urllib2
webHTML = urllib2.urlopen('http://hobbyking.com/hobbyking/store/__39036__Turnigy_Multistar_2213_980Kv_14Pole_Multi_Rotor_Outrunner.html').read()
webHTML = lxml.html.fromstring(webHTML)
productDetails = webHTML.get_element_by_id('productDetails')
for element in productDetails:
print element.text_content()
当我使用元素_id为'mm3'或接近顶部的元素时,这将给出预期的输出,但是如果我使用元素_id'productDetails',则没有输出。至少我现在的设置是这样的。在
恐怕
lxml.html
无法解析这个特定的HTML源代码。它将带有id="productDetails"
的h3
标记解析为空元素(这在default "recover" mode中):用^{} parser 切换到^{} (这是一个非常宽大的):
^{pr2}$印刷品:
相关问题 更多 >
编程相关推荐