Scrapy
爬蟲時,由於重定向或是其他原因,會導致原始的start_url
改變,怎樣才能得到原始的start_url##?
#
def start_requests(self):
start_url = 'your_scrapy_start_url'
yield Request(start_url, self.parse)
def parse(self, response):
item = YourItem()
item['start_url'] = 原始请求的start_url
yield item
为情所困2017-06-28 09:25:41
參考文章:Scrapy爬蟲常見問題摘要
利用Request
中的meta
參數傳遞訊息
def start_requests(self):
start_url = 'your_scrapy_start_url'
yield Request(start_url, self.parse, meta={'start_url':start_url})
def parse(self, response):
item = YourItem()
item['start_url'] = response.meta['start_url']
yield item