私はXMLFeedSpider
を使用しているスクラピースパイダーを持っています。 parse_node()
の各ノードで返されたデータだけでなく、さらにデータを取得するために追加のリクエストを行う必要があります。私が得た場合にのみ、問題は、parse_node()
何からの追加の要求は全く返されますされていますScrapy - XMLFeedSpiderで追加のリクエストを行うことができません
class MySpidersSpider(XMLFeedSpider):
name = "myspiders"
namespaces = [('g', 'http://base.google.com/ns/1.0')]
allowed_domains = {"www.myspiders.com"}
start_urls = [
"https://www.myspiders.com/productMap.xml"
]
iterator = 'iternodes'
itertag = 'item'
def parse_node(self, response, node):
if(self.settings['CLOSESPIDER_ITEMCOUNT'] and int(self.settings['CLOSESPIDER_ITEMCOUNT']) == self.item_count):
raise CloseSpider('CLOSESPIDER_ITEMCOUNT limit reached - ' + str(self.settings['CLOSESPIDER_ITEMCOUNT']))
else:
self.item_count += 1
id = node.xpath('id/text()').extract()
title = node.xpath('title/text()').extract()
link = node.xpath('link/text()').extract()
image_link = node.xpath('g:image_link/text()').extract()
gtin = node.xpath('g:gtin/text()').extract()
product_type = node.xpath('g:product_type/text()').extract()
price = node.xpath('g:price/text()').extract()
sale_price = node.xpath('g:sale_price/text()').extract()
availability = node.xpath('g:availability/text()').extract()
item = MySpidersItem()
item['id'] = id[0]
item['title'] = title[0]
item['link'] = link[0]
item['image_link'] = image_link[0]
item['gtin'] = gtin[0]
item['product_type'] = product_type[0]
item['price'] = price[0]
item['sale_price'] = '' if len(sale_price) == 0 else sale_price[0]
item['availability'] = availability[0]
yield Request(item['link'], callback=self.parse_details, meta={'item': item})
def parse_details(self, response):
item = response.meta['item']
item['price_per'] = 'test'
return item
私はreturn item
にparse_node()
の最後の行を変更した場合、それは(当然、項目にprice_per
を設定せずに)正常に動作します。
私が間違っていることを知っていますか?
はい、URLは解決可能です - 私はデバッグする場合、私は私のブラウザでリンクURLの罰金にアクセスすることができます。また、リンクを 'http:// httpbin.org /'のような任意のものに変更しましたが、私のコールバックはヒットしません(または返されたアイテム)。 – BrynJ