如何重复一个重复的请求

2024-03-29 13:36:02 发布

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

当我向scrapeapi发送请求时,它有时无法正确加载,它返回我-1而不是价格。在

所以我设置了一个while循环,让它在得到-1时重复请求,但是由于重复请求,spider在第一个请求之后停止。在

所以我的问题是,如何更改它来处理重复请求?在

示例代码:

     is_checked = False
     while(not is_checked):
         response = yield scrapy.Request("https://api.bookscouter.com/v3/prices/sell/"+isbn+".json")            
         jsonresponse = loads(response.body)
         sellPrice = jsonresponse['data']['Prices'][0]['Price']
         if sellPrice!=-1:
             is_checked = True
             yield {'SellPrice': sellPrice}

请记住,我使用内联请求库,但它与解决方案无关。在


Tags: 代码false示例isresponsenot价格jsonresponse