-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_img.py
32 lines (29 loc) · 981 Bytes
/
get_img.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
"""
model: image_download
"""
import os
import requests
import time
def get_file():
os.chdir(r'/home/coding/workspace/PyWeb/img') # TODO: 此处路径请自行修改
f = open('../http.txt', 'r')
num = 0
headers = {'Accept': '*/*',
'Accept-Language': 'zh-CN,en;q=0.8',
'Cache-Control': 'max-age=0',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',
'Connection': 'keep-alive',
'Referer': 'http://www.baidu.com/'
}
for i in f.readlines():
application = i[-4:-1]
res = requests.get(i, headers)
content = res.content
path_content = time.time()
img = open('%d%s.%s' % (num, path_content, application), 'wb+')
img.write(content)
img.close()
print('download : %s' % i)
num += 1
f = open('../http.txt', 'w+')
f.close()