1. 程式人生 > >python3 fiddler 下載app掌上英雄聯盟的英雄圖片

python3 fiddler 下載app掌上英雄聯盟的英雄圖片

 上程式碼 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)