我正在使用Python通过ScraperWiki创建一个刮板,但是我的结果有问题。我的代码是基于基本实例的ScraperWiki的文档编写的,一切看起来都很相似,所以我不知道我的问题在哪里。对于我的结果,我得到了页面上的第一个文档标题/URL,但是这个循环似乎有一个问题,因为它不会在那个之后返回其余的文档。如有任何建议,敬请谅解!
import scraperwiki
import requests
import lxml.html
html = requests.get("http://www.store.com/us/a/productDetail/a/910271.htm").content
dom = lxml.html.fromstring(html)
for entry in dom.cssselect('.downloads'):
document = {
'title': entry.cssselect('a')[0].text_content(),
'url': entry.cssselect('a')[0].get('href')
}
print document发布于 2014-09-29 21:40:53
您需要使用类a迭代div中的downloads标记。
for entry in dom.cssselect('.downloads a'):
document = {
'title': entry.text_content(),
'url': entry.get('href')
}
print document指纹:
{'url': '/webassets/kpna/catalog/pdf/en/1012741_4.pdf', 'title': 'Rough In/Spec Sheet'}
{'url': '/webassets/kpna/catalog/pdf/en/1012741_2.pdf', 'title': 'Installation and Care Guide with Service Parts'}
{'url': '/webassets/kpna/catalog/pdf/en/1204921_2.pdf', 'title': 'Installation and Care Guide without Service Parts'}
{'url': '/webassets/kpna/catalog/pdf/en/1011610_2.pdf', 'title': 'Installation Guide without Service Parts'}https://stackoverflow.com/questions/26109327
复制相似问题