1

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
4

1 に答える 1

1

with クラスa内のタグを反復処理する必要があります。divdownloads

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'}
于 2014-09-29T21:40:53.510 に答える