懂车帝官方API接口分析和部分网页解析分析
-
世界上最幸福的事情莫过于爬虫时
F12
可以找到一个官方的API接口🤡 -
❗ 该文档仅用于学习交流,未用于其它任何途径
官方API接口分析
🔨:该接口由于官方在11月27号左右更新网址的时候已经隐藏,但是依然可以请求到数据
-
请求方式:GET
-
请求参数说明:
字段名 字段说明 字段类型 备注 是否必填 month 销量榜时间 int 1000:表示一年 500:表示半年 202108:表示2021年8月 是 count 返回的数据量 int 100:返回100辆车的数据 是 new_energy_type 新能源汽车 int 1:纯电动 2:插电式混动 否 city 城市名称 varchar 无 否 rank_data_type 销量榜 int 11:销量榜 是 -
响应示例
-
获取新能源汽车销量榜
-
响应结果
{ "prompts": "", "status": 0, "message": "success", "data": { "head_info": { "title": "", "text": "" }, "paging": { "count": 1, "has_more": true, "offset": 0, "total": 0 }, "list": [ { "series_id": 4499, "series_name": "五菱宏光MINIEV", "image": "http://p1-dcd.byteimg.com/img/motor-img/6efbde874de291b8176fa27814b9bef3~tplv-resize:240:0.png", "rank": 1, "min_price": 2.88, "max_price": 4.86, "last_rank": -1, "count": 380278, "score": 0, "car_review_count": 399, "text": "", "show_trend": true, "descender_price": 0, "offline_car_ids": [ ], "online_car_ids": [ ], "series_pic_count": 2427, "brand_id": 39, "outter_detail_type": 0, "brand_name": "五菱汽车", "sub_brand_id": 198, "sub_brand_name": "上汽通用五菱", "price": "2.88-4.86万", "dealer_price": "2.88-4.86万", "has_dealer_price": true } ], "sells_rank_month": [ { "text": "2021年11月", "month": 202111 }, { "text": "2021年10月", "month": 202110 }, { "text": "2021年09月", "month": 202109 }, { "text": "2021年08月", "month": 202108 }, { "text": "2021年07月", "month": 202107 }, { "text": "2021年06月", "month": 202106 }, { "text": "近半年", "month": 500 }, { "text": "近一年", "month": 1000 } ] } }
-
官方网页渲染对应位置
-
其它URL测试
-
懂车分页面解析
-
页面URL地址(以五菱宏光MINIEV为例)
-
URL地址分析
在该页面URL中数字
4499
代表每款汽车的序列号,该序列号可以通过在官方API接口的请求返回的JSON数据中获得其字段名为series_id
。通过该字段去构造请求URL地址,即可获得汽车的懂车分的页面信息。def getScore(seriesId): url = f"https://www.dongchedi.com/auto/series/score/{seriesId}-x-x-x-x-x-x" response = requestData(url, headers) if (response != 0): return response
-
获取懂车分信息表关键代码
def analysisScore(seriesId, seriesName, *tableField: list): doc = pq(dcdReq.getScore(seriesId)) elements = doc(".tw-h-94") score = [] score.append(seriesId) score.append(seriesName) for element in elements.items(): items = [li.text() for li in element.items('li')] score.append(items[1]) if tableField: return dict(zip(tableField[0], score)) else: return score