从spid中调用spider

2024-09-28 22:33:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个尖刺刮网页,并获得所有的网址。在

我有另一个spiner,它有一个网址和废品。在

我想为第一个链接调用第二个spiner。在

从第一个spiner获取所有链接的代码

for site in sites:
            Link = site.xpath('a/@href').extract()

但我不知道如何为每个Link调用spiner

请帮忙


Tags: 代码in网页for链接linksiteextract
1条回答
网友
1楼 · 发布于 2024-09-28 22:33:10

我想你最好把这两个蜘蛛联合起来做些类似的事情:

def get_links(self, response):
    for site in sites:
        link = site.xpath('a/@href').extract()[0]
        yield Request(url=link, callback=self.scrape_them)

def scrape_them(self, response):
    # by now scrapy called the link and you get the response
    ...

相关问题 更多 >