我有一个 scrapy 脚本
- 查找 xml 文件中的所有“页面”节点
- 解析所有这些页面,收集数据,查找其他页面
- 进一步解析其他页面并收集信息
Scrapy 脚本:
class test_spider(XMLFeedSpider):
name='test'
start_urls=['https://www.example.com']
custom_settings={
'ITEM_PIPELINES':{
'test.test_pipe': 100,
},
}
itertag='pages'
def parse1(self,response,node):
yield Request('https://www.example.com/'+node.xpath('@id').extract_first()+'/xml-out',callback=self.parse2)
def parse2(self,response):
yield{'COLLECT1':response.xpath('/@id').extract_first()}
for text in string.split(response.xpath(root+'/node[@id="page"]/text()').extract_first() or '','^'):
if text is not '':
yield Request(
'https://www.example.com/'+text,
callback=self.parse3,
dont_filter=True
)
def parse3(self,response):
yield{'COLLECT2':response.xpath('/@id').extract_first()}
class listings_pipe(object):
def process_item(self,item,spider):
pprint(item)
理想的结果是组合字典项目,例如
{'COLLECT1':'some data','COLLECT2':['some data','some data',...]}
有没有办法在每个 parse1 事件之后调用管道?并获取项目的组合字典?
最佳答案
在您的 Parse2
方法中,使用 meta
并使用 meta< 将
。然后在collection1
传递给 parse3
/Parse3
中获取您的collection1
,提取
您的collection2
并根据您的意愿产生组合结果。
有关元的更多信息,您可以阅读 here
关于python - Scrapy 合并来自多个进程的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54140716/