当我使用lmxl解析一个web时,lxml-xpath可以得到target的一部分,请看我的代码:
import urllib
import lxml.html
url="http://sc.hkex.com.hk/gb/www.hkex.com.hk/chi/market/sec_tradinfo/stockcode/eisdeqty_c.htm"
file=urllib.urlopen(url).read()
root=lxml.html.document_fromstring(file)
for company in root.xpath('//tr[@class="tr_normal"]'):
print company.text_content().encode('utf-8')
>>>00325创生控股1,000#
00326中国星集团50,000#
00327百富环球1,000
00328ALCO HOLDINGS2,000#
00329
>>> 有两个问题:
1.为什么我只能得到000329?对方失去了?
2.为什么拿不到编码大于000329的公司信息?

发布于 2012-09-06 15:44:03
read()不会一次读取整个页面。您需要对其进行迭代
从文档中:
如果size参数被省略或为负数,则
()方法在数据流结束之前可能无法读取;在一般情况下,没有好的方法来确定是否已读取来自套接字的整个流。
https://stackoverflow.com/questions/12294355
复制相似问题