这是我的代码:
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输出如下:
但当它屈服于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.com
,www.apple.com
,www.rest.com
)
请引导我谢谢!在
默认情况下,未定义计划和发送报废请求的顺序。但是,您可以使用^{} keyword argument 来控制它:
您还可以通过在
meta
字典中传递callstack
使爬行同步,例如请参见this answer。在相关问题 更多 >
编程相关推荐