-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwz.py
More file actions
66 lines (57 loc) · 2.08 KB
/
wz.py
File metadata and controls
66 lines (57 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
import os
import re
import requests
from bs4 import BeautifulSoup
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
baseurl = 'http://pvp.qq.com/web201605'
mainurl = 'http://pvp.qq.com/web201605/herolist.shtml'
herolist = []
def getHeroList():
'''取所以英雄存入list中'''
hero = {}
res = requests.get(mainurl)
sp = BeautifulSoup(res.content, "html.parser")
lists = sp.select('body > div.wrapper > div > div > div.herolist-box > div.herolist-content > ul > li')
for li in lists:
oj = li.select('a')[0];
hero['url'] = oj['href']
hero['name'] = oj.text
# 正则表达式取ename编号
ename = re.findall('herodetail/(\d+)\.shtml', oj['href'])[0]
hero['ename'] = ename
herolist.append(hero)
hero = {}
return herolist
def saveImg(filepath, imgUrl):
'''下载图片并保存'''
r = requests.get(imgUrl, stream=True)
with open(filepath, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
f.flush()
f.close()
if __name__ == '__main__':
hlist = getHeroList()
for hero in herolist:
herodir = os.path.join(os.getcwd(), hero['name'])
heropage = baseurl + '/' + hero['url']
print('[%s]' % (herodir))
res = requests.get(heropage)
sop = BeautifulSoup(res.content, "html.parser")
li = sop.select('body > div.wrapper > div.zk-con1.zk-con > div > div > div.pic-pf > ul ')[0]['data-imgname']
li = str(li).split('|')
print(li)
# 遍历所有皮肤
for i in range(len(li)):
imgurl = 'http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/' \
+ hero['ename'] + '/' + hero['ename'] + '-bigskin-' + str(i + 1) + '.jpg'
imgname = os.path.join(herodir, li[i] + ".jpg")
print('----[%s]--[%s]---' % (imgname, imgurl))
# 创建英雄目录
if os.path.exists(herodir) == False:
os.mkdir(herodir)
saveImg(imgname, imgurl)