[英]How do I parse a response using a global variable in Scrapy?
I modified my start_requets method to be: 我将start_requets方法修改为:
def start_requests(self):
array = list(open("file", 'r'))
for i in array:
yield self.make_requests_from_url("http://example.org/test.php?id=" + i)
How can I access the value of i in the parse method? 如何在解析方法中访问i的值?
I tried setting a global variable idd and adding 我尝试设置全局变量idd并添加
global idd
idd = i
in the start_requests method and then 在start_requests方法中,然后
def parse(self, response):
item = DataItem()
item['id'] = idd
But all of items' id fields were filled with idd's last value. 但是所有项目的id字段都填充了idd的最后一个值。
How do I fix this? 我该如何解决?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.