爬取lol皮肤
#!/usr/bin/python # -*- coding: utf-8 -*- # data:2018-11-23 # user:fei import re import requests import json,random def path_js(url_js): res_js = requests.get(url=url_js).content html_js = res_js.decode("gbk") req = '"keys":(.*?),"data"' req = re.compile(req) list_js = re.findall(req,html_js) # print(list_js) dict_js = json.loads(list_js[0]) return dict_js def path_url(dict_js): for key in dict_js: for item in range(20): nums = str(item) if len(nums) == 1: names_str = "big" + key + "00" + nums + ".jpg" elif len(nums) == 2: names_str = "big" + key + "0" + nums + ".jpg" url = "http://ossweb-img.qq.com/images/lol/web201310/skin/%s" %names_str # header = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'} path = "F:/360downloads/boot/photo/%s" %names_str head_list = [ 'MSIE (MSIE 6.0; X11; Linux; i686) Opera 7.23', 'Opera/9.20 (Macintosh; Intel Mac OS X; U; en)', 'Opera/9.0 (Macintosh; PPC Mac OS X; U; en)', 'iTunes/9.0.3 (Macintosh; U; Intel Mac OS X 10_6_2; en-ca)', 'Mozilla/4.76 [en_jp] (X11; U; SunOS 5.8 sun4u)', 'iTunes/4.2 (Macintosh; U; PPC Mac OS X 10.2)', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20100101 Firefox/5.0', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0) Gecko/20100101 Firefox/9.0', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20120813 Firefox/16.0', 'Mozilla/4.77 [en] (X11; I; IRIX;64 6.5 IP30)', 'Mozilla/4.8 [en] (X11; U; SunOS; 5.7 sun4u)' ] # heade = random.choice(head_list) header = {'User-Agent': random.choice(head_list)} # print(heade) img_file = requests.get(url, headers=header) if img_file.status_code == 404: pass else: print("正在存储图片" + url) with open(path,"wb") as f: f.write(img_file.content) # if __name__ == '__main__': url_js = "https://lol.qq.com/biz/hero/champion.js" dict_js = path_js(url_js) url = path_url(dict_js)