Scrapy Redirect_urls Exception.keyerror
I am new to Scrapy & Python, recently launched my first spider. There is a feature that seems to have worked before though now it only works for some of the websites I am tryin
Solution 1:
So, response.request.meta['redirect_urls']
is set by the RedirectMiddleware to any URLs that the request may have gone through while being redirected.
For requests that haven't been redirected, that code will fail with a KeyError
.
Since response.request.meta
is just a dict, you can use:
item['url_direct'] = response.request.meta.get('redirect_urls')
Or you can check it before setting:
if'redirect_urls'in response.request.meta:
item['url_direct'] = response.request.meta['redirect_urls']
Post a Comment for "Scrapy Redirect_urls Exception.keyerror"