【发布时间】:2017-10-02 12:02:42
【问题描述】:
当我向抓取 API 发送请求时,有时它无法正确加载,它返回给我 -1 而不是价格。
所以我放了一个while循环让它重复请求,只要我得到-1,但由于重复请求,蜘蛛在第一个请求后停止。
所以我的问题是,如何更改它以处理重复请求?
示例代码:
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}
请记住,我使用内联请求库,但它与解决方案无关。
【问题讨论】:
标签: python web-scraping scrapy web-crawler