Python爬取Carmax数据

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值