下载王者荣耀皮肤高清图片

import requests

from lxml import etree

import os

from time import sleep

headers={

 

    'user-agent': '填自己的'

}

hero_list_url='https://pvp.qq.com/web201605/js/herolist.json'

hero_list_url_res=requests.get(hero_list_url,headers=headers)

#print(hero_list_url_res.json())

for h in hero_list_url_res.json():

    ename=h.get('ename')

    cname=h.get('cname')

    if not os.path.exists(cname):

        os.makedirs(cname)

 

    #访问英雄主页

    hero_info_url=f'https://pvp.qq.com/web201605/herodetail/{ename}.shtml'

    hero_info_res=requests.get(hero_info_url,headers=headers)

    hero_info_res.encoding='gbk'

    e=etree.HTML(hero_info_res.text)

    names=e.xpath('//ul[@class="pic-pf-list pic-pf-list3"]/@data-imgname')[0]

    #皮肤名字

    names=[name[0:name.index('&')] for name in names.split('|')]

    for i,n in enumerate(names):

        url = f'https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/{ename}/{ename}-bigskin-{i+1}.jpg'

        res=requests.get(url,headers=headers)

        with open(f'{cname}/{n}.jpg','wb') as f:

            f.write(res.content)

        print(f'已下载{n}')

        sleep(1)

 

你可能感兴趣的:(python)