import os import json import re import requests def Pifu_Pic(): Main_js="http://lol.qq.com/biz/hero/champion.js"#返回英雄ID号和英雄的名字 Hero_link="http://ossweb-img.qq.com/images/lol/web201310/skin/big"#103002.jpg"英雄皮肤的链接,103为英雄ID号,002为图片序列号 resource=requests.get(Main_js) Total_data = resource.content.decode() req=r'"keys":(.*?),"data":' List_data=re.findall(req,Total_data) Dict_data=json.loads(List_data[0]) Hero_Links=[] for heroid,heroname in Dict_data.items(): for i in range(20): num=str(i) if len(num)==1: Hero_Links.append(Hero_link+heroid+"00"+num+".jpg") elif len(num)==2: Hero_Links.append(Hero_link+heroid+"0"+num+".jpg") for Get_Pic in Hero_Links: Pic_Response=requests.get(Get_Pic) if Pic_Response.status_code==200: leng=len(Get_Pic)-54 Pic_Hero_id=Get_Pic[-leng:-7] Pic_Hero_num=Get_Pic[-7:-4] Pic_Hero_name=Dict_data[Pic_Hero_id] if not os.path.exists('./pic'): os.mkdir('pic') with open ('./pic/'+Pic_Hero_name+Pic_Hero_num+'.jpg','ab') as f: Pic_data=requests.get(Get_Pic) f.write(Pic_data.content) if __name__ == '__main__': Pifu_Pic()