Python爬取英雄联盟官网壁纸源码分享

import json
import re

import requests
import time
def getLOLImages():
header = {‘User-Agent’:‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36’}
url_js = ‘http://lol.qq.com/biz/hero/champion.js’
#获取JS源代码 Str bytes
res_js = requests.get(url_js).content
#转码 转成字符串
html_js = res_js.decode()
#正则表达式
req = ‘“keys”?.*?),“data”’
list_js = re.findall(req,html_js)
dict_js=json.loads(list_js[0])
pic_list=[]
for key in dict_js:
for i in range(20):
number=str(i)
if len(number)==1:
hero_num=“00”+number
elif len(number)==2:
hero_num=“0”+number
numstr=key+hero_num
url=“http://ossweb-img.qq.com/images/lol/web201310/skin/big"+numstr+".jpg”
pic_list.append(url)
list_filepath=[]
#需要输入自己对应的文件路径不然,如果输入的文件路径不存在会报错
path=“D:\Pycharmdaima\Pachong\LOLTU\”
for name in dict_js.values():
for i in range(20):
file_path=path+name+str(i)+’.jpg’
list_filepath.append(file_path)

n=0
for picurl in pic_list:
res=requests.get(picurl)
n+=1
if res.status_code==200:
print(“正在下载%s”%list_filepath[n])
time.sleep(1)
with open(list_filepath[n],‘wb’) as f:
f.write(res.content)
getLOLImages()

你可能感兴趣的:(Python爬取英雄联盟官网壁纸源码分享)