import requests
import re
import xlwt
Page=1
zip=94701
StartIndex=0
#url1="https://www.carmax.com/search#Distance=all&Page=3&Zip=90470"
book = xlwt.Workbook(encoding='utf-8',style_compression=0)
sheet=book.add_sheet('dk',cell_overwrite_ok=True)
for Page in range(1,19):
try:
StartIndex=(Page-1)*20
url="https://api.carmax.com/v1/api/vehicles/?SortKey=0&Distance=all&Refinements=4294962106&PerPage=20&Zip=94701&ExposedDimensions=249+265+250+772&Page="+str(Page)+"&StartIndex="+str(StartIndex)+"&ExposedCategories=249+265+250+772&platform=carmax.com&apikey=adfb3ba2-b212-411e-89e1-35adab91b600"
html=requests.get(url).content
except Exception,e:
print e
StockNumber=re.findall("\"StockNumber\":(.*?),",html,re.S)
Year=re.findall("\"Year\":(.*?),",html,re.S)
Description=re.findall("\"Description\":\"(.*?)\",",html,re.S)
Miles=re.findall("\"Miles\":\"(.*?)\",",html,re.S)
Price=re.findall("\"Price\":(.*?),",html,re.S)
for i in range(0,len(StockNumber)):
row=Page*i
sheet.write(row,0,StockNumber[i])
sheet.write(row,1,Year[i])
sheet.write(row,2,Description[i])
sheet.write(row,3,Miles[i])
sheet.write(row,4,Price[i])
book.save('C:\Users\DeNgKe\Desktop\mini cooper.xls')
# content=requests.get(url).content
# print content
Python爬取Carmax数据
最新推荐文章于 2024-09-18 20:39:31 发布