import requests
import time
import random
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.104 Safari/537.36"
}
def getrandom():
return random.uniform(1,5)#生成一个指定范围内的浮点数
def get_slug():
url = "https://yz.lol.qq.com/v1/zh_cn/search/index.json"
res = requests.get(url, headers=headers).json()
lol_list = res["champions"]
list1 = []
for lol in lol_list:
list1.append(lol["slug"])
return list1
def get_stroy(lol_lists):
for i in lol_lists:
sec = getrandom()
time.sleep(sec)
print("--have sleep -- = -- %lf" %sec)
url = "https://yz.lol.qq.com/v1/zh_cn/champions/{}/index.json".format(i)
print(url)
response = requests.get(url, headers = headers).json()
stroy = response["champion"]
item = {}
item["name"] = i
item["biography_full"] = stroy["biography"]["full"]
print(item)
if item["biography_full"]:
con = item["biography_full"]
try:
with open("story/" + item["name"] + item["slug"] + ".text","w", encoding='gb18030', errors='ignore') as f:
f.write(con)
except IOError:
print("IOError")
else:
print("正在下载%s" %item["name"])
else:
print("没有数据")
lol_lists = get_slug()
get_stroy(lol_lists)
print("下载完成!!!")
Python 获取LOL所有英雄的传说
猜你喜欢
转载自blog.csdn.net/c_lanxiaofang/article/details/103964913
今日推荐
周排行