上代码 fodder 安装请看这里 https://blog.csdn.net/limingyue0312/article/details/81808688
#-*- coding: UTF-8 -*-
from urllib.request import urlretrieve
import requests
import os
"""
函数说明:下载《掌上英雄联盟》中的英雄图片
Parameters:
heros_url - GET请求地址,通过Fiddler抓包获取
header - header信息
Returns:
无
Author:
yue909
"""
def hero_imgs_download(heros_url,header):
req = requests.get(url = heros_url, headers = header).json()
# print(req['data']['goods'])
hero_num = len(req['data']['goods'])
print('一共有%d个英雄' %hero_num)
hero_images_path = 'yxlmhero_images'
for each_hero in req['data']['goods']:
hero_photo_url = each_hero['sGoodsPic']
hero_name = each_hero['sGoodsName'] + '.jpg'
filename = hero_images_path + '/' + hero_name
if hero_images_path not in os.listdir():
os.makedirs(hero_images_path)
urlretrieve(url = hero_photo_url, filename = filename)
if __name__ == '__main__':
headers = {'Accept-Charset': 'UTF-8',
'Accept-Encoding': 'gzip,deflate',
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 6.0.1; MI 5 MIUI/V8.1.6.0.MAACNDI)',
'X-Requested-With': 'XMLHttpRequest',
'Content-type': 'application/x-www-form-urlencoded',
'Connection': 'Keep-Alive',
'Host': 'apps.game.qq.com',
'Accept-Encoding': 'gzip'
}
for i in range(1,20):
heros_url = "http://apps.game.qq.com/daoju/go/zmgoods/list?cat=16&page=%d&plat=android&version=9811"%i
hero_imgs_download(heros_url,headers)