如何在scrapy中获取原始的start_url(在重定向之前)

use*_*000 9 python redirect scrapy web-scraping

我正在使用Scrapy抓取一些页面.我从excel表中获取start_urls,我需要将url保存在项目中.

class abc_Spider(BaseSpider):
   name = 'abc'
   allowed_domains = ['abc.com']         
   wb = xlrd.open_workbook(path + '/somefile.xlsx')
   wb.sheet_names()
   sh = wb.sheet_by_name(u'Sheet1')
   first_column = sh.col_values(15)
   start_urls = first_column
   handle_httpstatus_list = [404]

   def parse(self, response):
      item = abcspiderItem()
      item['url'] = response.url
Run Code Online (Sandbox Code Playgroud)

问题是url被重定向到其他url(因此在响应url中提供了其他内容).如何获取我从excel获得的原始URL?

ale*_*cxe 17

你可以找到你需要的东西response.request.meta['redirect_urls'].

文档引用:

可以在redirect_urls Request.meta键中找到请求经过的URL(在重定向时).

希望有所帮助.