cari

Rumah  >  Soal Jawab  >  teks badan

python - scrapy 再次请求的问题

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

天蓬老师天蓬老师2785 hari yang lalu791

membalas semua(1)saya akan balas

  • 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

    Akhirnya dilampirkan dokumen rasmi https://doc.scrapy.org/en/lat...
    Versi terjemahan bahasa Cina http://scrapy-chs.readthedocs...

    balas
    0
  • Batalbalas