## Python 懂车帝综合口碑数据
### 需求
懂车帝全系车型综合口碑 优点 缺点 统计数据
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/eda7f733349e4e5c92365ef8953b60a0.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5ouJ54Gv55qE5bCP5omL,size_20,color_FFFFFF,t_70,g_se,x_16)
### 操作环境
- win10
- Google nexus5x(root)
- Python3.9
- Charles
### 需求分析
先来web端试下能否找到需要的数据接口,随便找个车型打开口碑页面F12查看Network
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/8167b0924fee4130940c2cbc8ec0cbf2.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5ouJ54Gv55qE5bCP5omL,size_20,color_FFFFFF,t_70,g_se,x_16)
根据页面关键词搜索没有找到明显的数据接口,虽然说现在也可以使用request或者selenium直接在页面解析数据,但是毕竟这不是首选方案,还是从APP分析一下在决定用什么方案。
PS:手机环境、抓包环境的配置在这不在赘述,有兴趣的可参考之前的文章 [APP抓包环境配置](https://cenjy.blog.csdn.net/article/details/123635939)
下载懂车帝APP,并安装至手机
![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/43d931bba35b499aa179123e79c453f8.png)
手机开启Postern,pc打开charles
至此抓包工作准备完成,打开懂车帝APP,随便找个车型进入懂车分页面
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/6707b47da4b94884863ad17880a11d14.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5ouJ54Gv55qE5bCP5omL,size_13,color_FFFFFF,t_70,g_se,x_16)
还是老套路先根据页面关键词搜索一波
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/8a727c1b753e4ed497983376d7fd2f57.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5ouJ54Gv55qE5bCP5omL,size_15,color_FFFFFF,t_70,g_se,x_16)
明显看出来后两条数据不是需要的,前四条是同一个接口返回的,应该就是需要的数据,双击点进去看一下详细数据
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/4cf47a9eb2364c1591f2c798301684b3.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5ouJ54Gv55qE5bCP5omL,size_20,color_FFFFFF,t_70,g_se,x_16)
初步查看和页面数据是一致的,看数据结构和具体的数值和页面中的数据很像,Charles界面太小,将数据拷贝至网页中解析,方便分析,分享一个常用的[json数据在线解析网站](https://www.bejson.com/jsonviewernew/?tdsourcetag=s_pcqq_aiomsg)
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/52f971ac7162456ba50ef21a45d3f5af.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5ouJ54Gv55qE5bCP5omL,size_20,color_FFFFFF,t_70,g_se,x_16)
经过仔细对比页面中的数据,发现此接口就是我们需要的
综合口碑接口:
```
https://*******/get_detail/?series_id=4182&car_id=0&only_owner=0&year_id=all&iid=2467735824764398&device_id=40011211486215&ac=wifi&channel=dcd-yd-11zh-and-74&aid=36&app_name=automobile&version_code=693&version_name=6.9.3&device_platform=android&os=android&ab_client=a1%2Cc2%2Ce1%2Cf2%2Cg2%2Cf7&ab_group=3167590%2C3577236%2C3333988&ssmix=a&device_type=Nexus+5X&device_brand=google&language=zh&os_api=27&os_version=8.1.0&manifest_version_code=693&resolution=1080*1794&dpi=420&update_version_code=6931&_rticket=1648907286543&cdid=f3163204-7faf-45d7-89c4-e82215c3216c&city_name=%E8%81%8A%E5%9F%8E&gps_city_name=%E8%81%8A%E5%9F%8E&selected_city_name&rom_version=27&longi_lati_type=1&longi_lati_time=1648907102913&content_sort_mode=0&total_memory=1.77&cpu_name=Qualcomm+Technologies%2C+Inc+MSM8992&overall_score=4.873&cpu_score=4.8872&host_abi=
```
对!你没看错,就是这么长,验证一下数据接口,在网页中直接请求一下这个url
![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/73fa607f3184429493fec52ba008da60.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5ouJ54Gv55qE5bCP5omL,size_20,color_FFFFFF,t_70,g_se,x_16)
这儿推荐安装一个网页json可视化的插件,这儿偷懒没装,在线解析了一下json数据,和Charles抓到的数据是一样,经过分析得知: series_id是车系id,修改此参数即可
### 获取全部车系id
获取车系id就很简单了,先拿到品牌id然后根据品牌id请求车系信息,注意这是一个post接口
```
def get_series(self, brand_id):
"""
获取品牌所有车系
brand_id:品牌id
"""
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36'}
param = {
'offset': 0,
'limit': 1000,
'is_refresh': 1,
'city_name': '北京',
'brand': brand_id
}
response = requests.post(url=url, data=param, headers=headers)
rep_json = json.loads(response.text)
# print(response.text)
if rep_json['status'] == 'success':
return rep_json['data']['series']
else:
raise Exception("get car series has exception!")
```
![请添加图片描述](https://ucc.alicdn.com/images/user-upload-01/9a6e78ead17c4e78ab18024dd4caf841.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5ouJ54Gv55qE5bCP5omL,size_20,color_FFFFFF,t_70,g_se,x_16)
### 获取车系综合口碑评分
```
def get_score(self, series_id):
"""
获取车系综合评分
series_id: 车系id
"""
response = self._parse_url(url).json()
tag_list = response.get('data').get('tab_info').get('tag_list')
data = list()
# 优点
merits = [i.get('tag_name')+"("+str(i.get('count'))+")" for i in tag_list if i.get('sentiment') == 1]
data.append(merits)
# 缺点
defects = [i.get('tag_name')+"("+str(i.get('count'))+")" for i in tag_list if i.get('sentiment') == -1]
data.append(defects)
return data
```
### 运行效果
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/d31d3fafab3f4ee294629bd3a3e238c2.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5ouJ54Gv55qE5bCP5omL,size_20,color_FFFFFF,t_70,g_se,x_16)
![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/38f621b6317d48c1a465d6617accf7c2.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5ouJ54Gv55qE5bCP5omL,size_20,color_FFFFFF,t_70,g_se,x_16)
### 资源下载
[https://download.csdn.net/download/qq_38154948/85073968](https://download.csdn.net/download/qq_38154948/85073968)
------
本文仅供学习交流使用,如侵立删! |
------