-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreadingPiture.py
43 lines (36 loc) · 1.21 KB
/
threadingPiture.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
43
import requests
import json
import urllib
from threading import Thread,Lock
class GetSogouImag(object):
def __init__(self):
pass
def getSogouImag(category,length,path):
n = length
cate = category
url = 'http://pic.sogou.com/pics/channel/getAllRecomPicByTag.jsp?category='+cate+'&tag=%E5%85%A8%E9%83%A8&start=0&len='+str(n)
imgs = requests.get(url)
jd = json.loads(imgs.text)
jd = jd['all_items']
imgs_url = []
for j in jd:
imgs_url.append(j['pic_url'])
m = 0
for img_url in imgs_url:
print('***** '+str(m)+'.jpg *****'+' Downloading...')
try:
urllib.request.urlretrieve(img_url,path+str(m)+'.jpg')
except:
print('图片迷路了')
else:
m = m + 1
print('Download complete!')
class DownLoadImg(thread):
if __name__ == "__main__":
title = input('请输入关键字: ')
t1 = Thread(target=getSogouImag, args=(title,2000,'d:/download/',))
t2 = Thread(target=getSogouImag, args=(title,2000,'d:/download/',))
t1.start()
t2.start()
t1.join()
t2.join()