こんばんは、助けてくれてありがとう。
私はScrappyを掘り下げています.Webサイトから情報を取得し、サイトの同じツリー構造を再作成する必要があります. 例:
books [
python [
first [
title = 'Title'
author = 'John Doe'
price = '200'
]
first [
title = 'Other Title'
author = 'Mary Doe'
price = '100'
]
]
php [
first [
title = 'PhpTitle'
author = 'John Smith'
price = '100'
]
first [
title = 'Php Other Title'
author = 'Mary Smith'
price = '300'
]
]
]
チュートリアルから、基本的なスパイダーを正しく実行しました:
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from pippo.items import PippoItem
class PippoSpider(BaseSpider):
name = "pippo"
allowed_domains = ["www.books.net"]
start_urls = [
"http://www.books.net/index.php"
]
def parse(self, response):
hxs = HtmlXPathSelector(response)
sites = hxs.select('//div[@id="28008_LeftPane"]/div/ul/li')
items = []
for site in sites:
item = PippoItem()
item['subject'] = site.select('a/b/text()').extract()
item['link'] = site.select('a/@href').extract()
items.append(item)
return items
私の問題は、私の構造のどのレベルもサイト内で 1 レベル深いため、基本レベルで必要な本の主題を取得した場合、対応する itemitem['link'] をクロールして他のアイテムを取得することです。しかし、次の URL では、データを正しく抽出するために別の HtmlXPathSelector が必要になります。構造の最後まで同様です。
基本的に私を助けて、私を正しい方法に置いていただけませんか?ありがとうございました。