-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path24-FilesDownload.py
42 lines (37 loc) · 1.13 KB
/
24-FilesDownload.py
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
'''
爬取文件集。
'''
import requests
import re,time,os
USER_NAMBER = 'yunzhan365' # 子路径
targetDir = 'result\\24-FilesDownload.py\\'+USER_NAMBER #文件保存路径
# 获取保存路径
def destFile(path,name=''):
if not os.path.isdir(targetDir):
os.makedirs(targetDir)
pos = path.rindex('/')
pom = path.rindex('.')
if name=='':
t = os.path.join(targetDir, path[pos+1:])
else:
t = os.path.join(targetDir, name + '.' + path[pom+1:])
return t
# 保存图片
def saveImage(imgUrl,name=''):
response = requests.get(imgUrl, stream=True)
image = response.content
imgPath = destFile(imgUrl,name)
try:
with open(imgPath ,"wb") as jpg:
jpg.write(image)
print('保存图片成功!%s' % imgPath)
return
except IOError:
print('保存图片成功!%s' % imgUrl)
return
finally:
jpg.close
if __name__=='__main__':
for n in range(1,99):
album_url = 'https://book.yunzhan365.com/pcqz/stgm/files/mobile/'+str(n)+'.jpg'
saveImage(album_url, str(n).zfill(4))