Scrapy 在解析中获取请求 url [英] Scrapy get request url in parse
本文介绍了Scrapy 在解析中获取请求 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 Scrapy 的 parse()
函数中获取请求 url?我在 start_urls
中有很多 url,其中一些将我的蜘蛛重定向到主页,结果我有一个空项目.所以我需要像 item['start_url'] = request.url
这样的东西来存储这些 url.我正在使用 BaseSpider.
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.
推荐答案
传递给 parse() 的 'response' 变量包含您想要的信息.您不需要覆盖任何内容.
The 'response' variable that's passed to parse() has the info you want. You shouldn't need to override anything.
例如.(已编辑)
def parse(self, response):
print "URL: " + response.request.url
这篇关于Scrapy 在解析中获取请求 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文