Mr .阳 2021-04-28 20:19 采纳率: 0%
浏览 41

scrapy中meta如何接收多个字典?

在第一个函数district_parse中,detail2是一个列表字典,里面包含多个字典,我想将这些字典作为参数循环传入meta,但总是只能传入第一个字典,有什么解决办法?

    def district_parse(self,response):
        item2 = response.meta["item"]
        Data2 = json.loads(re.findall(r'[(](.*?)[)]', response.text)[0])
        detail2 = Data2['data']['list']
        for loop1 in detail2:
            item2["district_time"] = loop1["timeHuman"]
            item2["district_name"] = loop1["district_name"]
            item2["district_congest"] = loop1["index"]
            item2["district_speed"] = loop1["speed"]
            item2["district_length"] = loop1["length"]

            url = "https://www.example.com"
            yield Request(url, meta={"item2": copy.deepcopy(item2)}, callback=self.curvehistory_parse)



    def curvehistory_parse(self,response):
        item3 = response.meta.get('item2')
        Data3 = json.loads(re.findall(r'[(](.*?)[)]', response.text)[0])
        detail3 = Data3['data']['list']
        for loop2 in detail3:
            item3["index"] = loop2["index"]
            item3["indexHis"] = loop2["indexHis"]
            item3["date"] = loop2["time"]
            yield copy.deepcopy(item3)
  • 写回答

3条回答 默认 最新

  • 关注

    district_parse函数中有 yield 说明是生成器函数,要用next()多次调用才行。

    或者用for循环调用。

    for res in self.district_parse(xxxxxxxx):

        pass

     

    如果你不是要生成器函数就不要用yield

     

    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计