如何通过命令生成url让scrapy

2024-09-26 23:23:49 发布

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

这是我的代码:

def parse(self, response):  
    selector = Selector(response)
    sites = selector.xpath("//h3[@class='r']/a/@href")
    for index, site in enumerate(sites):
        url =  result.group(1) 
        print url
        yield Request(url = site.extract(),callback = self.parsedetail)

def parsedetail(self,response):
    print response.url
    ...
    obj = Store.objects.filter(id=store_obj.id,add__isnull=True)
    if obj:
    obj.update(add=add)

def parse scarpy将从谷歌获得网址 url输出如下:

^{pr2}$

但当它屈服于def parsedetail url不是按顺序排列的,可能会变成:

www.rest.com
www.test.com
www.hahaha.com
www.apple.com

有没有办法让带订单的yield url发送到def parsedetail
因为我需要先抓取www.test.com(google search中最上面的url提供的数据更准确)
如果其中没有数据。
我将转到下一个url,直到更新空字段。(www.hahaha.comwww.apple.comwww.rest.com
请引导我谢谢!在


Tags: selfcomaddobjurlparseresponsedef
1条回答
网友
1楼 · 发布于 2024-09-26 23:23:49

默认情况下,未定义计划和发送报废请求的顺序。但是,您可以使用^{} keyword argument来控制它:

priority (int) – the priority of this request (defaults to 0). The priority is used by the scheduler to define the order used to process requests. Requests with a higher priority value will execute earlier. Negative values are allowed in order to indicate relatively low-priority.


您还可以通过在meta字典中传递callstack使爬行同步,例如请参见this answer。在

相关问题 更多 >

    热门问题