爬取王者荣耀官网皮肤【爬虫】
上次我们讲了爬虫的定义以及爬取王者荣耀皮肤的思路。
今天我们换一种方式来爬取同样的内容。大体上思路和方法一相同。
方法一传送门:方法一
方法二
# 网址:https://pvp.qq.com/web201605/js/herolist.json
import requests
import os
url = 'https://pvp.qq.com/web201605/js/herolist.json' # 英雄名字json 真实地址
html = requests.get(url)
html_json = html.json()
h_name = list(map(lambda x:x['cname'],html_json)) # 英雄名字
h_num = list(map(lambda x:x['ename'],html_json)) # 英雄数字
def timi():
x = 0
for i in h_num:
os.mkdir("F:\\PythonProject\\爬虫\\王者荣耀\\Skins\\"+h_name[x])
os.chdir("F:\\PythonProject\\爬虫\\王者荣耀\\Skins\\"+h_name[x])
x += 1
for j in range(12): # 第几张皮肤
a = 'https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/{}/{}-bigskin-{}.jpg'.format(i,i,j)
img = requests.get(a)
if img.status_code == 200:
open(str(j)+'.jpg','wb').write(img.content)
print('下载'+h_name[x]+'第'+str(j)+'张皮肤成功')
else:
continue
timi()
print('全部下载完毕')
效果展示