search

Home  >  Q&A  >  body text

python - scrapy 再次请求的问题

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

天蓬老师天蓬老师2786 days ago796

reply all(1)I'll reply

  • 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

    Finally attached is the official document https://doc.scrapy.org/en/lat...
    Chinese translation version http://scrapy-chs.readthedocs...

    reply
    0
  • Cancelreply