Request回调函数
def parse_page1(self, response):
return scrapy.Request("http://www.example.com/some_page.html",
callback=self.parse_page2)
def parse_page2(self, response):
# this would log http://www.example.com/some_page.html
self.logger.info("Visited %s", response.url)
传递参数
def parse_page1(self, response):
item = MyItem()
item['name'] = response.css('.name::text').extract_first()
request = scrapy.Request("http://www.example.com/some_page.html",
callback=self.parse_page2)
request.meta['item'] = item
yield request
def parse_page2(self, response):
item = response.meta['item']
item['age'] = response.css('.age::text').extract_first()
yield item
原文地址:https://www.cnblogs.com/hankleo/p/11909372.html
时间: 2024-10-29 13:17:09