正在抓取API“缺少平台源”

2024-04-24 10:07:27 发布

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

我在刮http://www.carwale.com/used/cars-in-mumbai/ 前20辆车和它们的数据都是html格式的,而且很容易被抓取。 我被卡在21+车上了——这是JSON。每增加20辆车的新页面的URL格式为“http://www.carwale.com/webapi/classified/stockfilters/?city=1&kms=0-&year=0-&budget=0-&pn=2”,pn迭代增加。在

enter image description hereenter image description here 我试过:

i = 2  
while i in range(totalcars/20+1):
    link = 'http://www.carwale.com/webapi/classified/stockfilters/?city=2&kms=0-&year=0-&budget=0-&pn='+str(i)
    response = urllib2.urlopen(link)
    data = json.load(response)   
    print data
    i += 1  

“HTTPError:HTTP Error 400:Bad Request”是响应

手动尝试此链接将返回“缺少平台源”

http://www.carwale.com/webapi/”返回“403-禁止:拒绝访问。”

访问这些数据的最有效的方法是什么?在


Tags: 数据incomhttpcitywww格式year