Maison  >  Questions et réponses  >  le corps du texte

python - scrapy 再次请求的问题

如:item['url']=response.xpath('a/@href')分析出一个链接,
然后想从这个链接里的网页再获取一些元素,放入item['other']
应该怎么写,谢谢。

天蓬老师天蓬老师2720 Il y a quelques jours747

répondre à tous(1)je répondrai

  • PHP中文网

    PHP中文网2017-04-18 10:30:58

    def parse_page1(self, response):
        for url in urls:
            item = MyItem()
            item['url'] = url
            request = scrapy.Request(url,callback=self.parse_page2)
            # request = scrapy.Request("http://www.example.com/some_page.html",dont_filter=True,callback=self.parse_page2)
            request.meta['item'] = item
            yield request
    
    def parse_page2(self, response):
        item = response.meta['item']
        item['other'] = response.xpath('/other')
        yield item

    Enfin ci-joint le document officiel https://doc.scrapy.org/en/lat...
    Version de traduction chinoise http://scrapy-chs.readthedocs...

    répondre
    0
  • Annulerrépondre