File tree 1 file changed +49
-0
lines changed
1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ # get_heros.py
2
+ # 引入模块
3
+ import requests
4
+ import json
5
+ import os
6
+ import time
7
+
8
+ st = time .time () #程序开始时间
9
+ url = 'http://pvp.qq.com/web201605/js/herolist.json'
10
+ response = requests .get (url ).content
11
+
12
+ # 提取Json信息
13
+ jsonData = json .loads (response )
14
+ print (jsonData )
15
+
16
+ # 初始化下载数量
17
+ x = 0
18
+
19
+ #目录不存在则创建
20
+ hero_dir = '/Users/mm/python/python-examples/heros/imgs/'
21
+ if not os .path .exists (hero_dir ):
22
+ os .mkdir (hero_dir )
23
+
24
+ for m in range (len (jsonData )):
25
+ # 英雄编号
26
+ ename = jsonData [m ]['ename' ]
27
+ # 英雄名称
28
+ cname = jsonData [m ]['cname' ]
29
+ # 皮肤名称,一般英雄会有多个皮肤
30
+ skinName = jsonData [m ]['skin_name' ].split ('|' )
31
+ # 皮肤数量
32
+ skinNumber = len (skinName )
33
+
34
+ # 循环遍历处理
35
+ for bigskin in range (1 ,skinNumber + 1 ):
36
+ # 拼接下载图片url
37
+ picUrl = 'http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/' + str (ename )+ '/' + str (ename )+ '-bigskin-' + str (bigskin )+ '.jpg'
38
+ #获取图片内容
39
+ picture = requests .get (picUrl ).content
40
+ # 保存图片
41
+ with open ( hero_dir + cname + "-" + skinName [bigskin - 1 ]+ '.jpg' ,'wb' ) as f :
42
+ f .write (picture )
43
+ x = x + 1
44
+ print ("当前下载第" + str (x )+ "张皮肤" )
45
+ # 获取结束时间
46
+ end = time .time ()
47
+ # 计算执行时间
48
+ exec_time = end - st
49
+ print ("找到并下载" + str (x )+ "张图片,总共用时" + str (exec_time )+ "秒。" )
You can’t perform that action at this time.
0 commit comments