Scrapy get request url in parse

Goran picture Goran · Nov 19, 2013 · Viewed 43.3k times · Source

How can I get the request url in Scrapy's parse() function? I have a lot of urls in start_urls and some of them redirect my spider to homepage and as result I have an empty item. So I need something like item['start_url'] = request.url to store these urls. I'm using the BaseSpider.

Answer

Jagu picture Jagu · Jan 25, 2015

The 'response' variable that's passed to parse() has the info you want. You shouldn't need to override anything.

eg. (EDITED)

def parse(self, response):
    print "URL: " + response.request.url