python爬虫:爬取所有车标图片保存本地

python爬虫:爬取所有车标图片保存本地

这次没想到会这么轻松,找了几个网站分析结构发现腾讯汽车的json接口,很轻松爬下所有的图标。上图:
python爬虫:爬取所有车标图片保存本地_第1张图片

总共209个牌子,以车牌子命名。

分析网页

一开始找了好几个网站,都没找到比较容易能获取数据的方式。还是腾讯这边比较给力,有现成的接口,json数据。

python爬虫:爬取所有车标图片保存本地_第2张图片

剩下的就简单了,只需要从json中获取数据就行。

all_car_url = 'https://api.ait.auto.qq.com/cardata/serial/all4oldpc'
response = requests.get(all_car_url, headers=headers)
print(response.status_code)
html_str = response.content.decode()
json_data = json.loads(html_str)
car_list = json_data['list']
for item in car_list:
    for car in item['BrandList']:
        url = 'https://img1.gtimg.com/datalib_img/' + car['brandLogo']
        save_img(car['brandName'], url)

这个爬虫的关键是在找到最合适的接口,真是让我惊喜…

你可能感兴趣的:(python爬虫,爬虫,python,json,html)