You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.2 KiB
117 lines
3.2 KiB
import requests
|
|
import os,random
|
|
from urllib import request
|
|
from multiprocessing import Pool
|
|
'''
|
|
#测试网站
|
|
http://httpbin.org/get
|
|
#代理网站
|
|
'''
|
|
url = 'https://image.baidu.com/search/acjson'
|
|
headers = {
|
|
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36'
|
|
}
|
|
|
|
|
|
|
|
|
|
def parse(kw,num):
|
|
|
|
infos = []
|
|
for i in range(30,30*num + 30,30):
|
|
try:
|
|
params = {
|
|
'tn': 'resultjson_com',
|
|
'ipn': 'rj',
|
|
'ct': '201326592',
|
|
'is':'',
|
|
'fp': 'result',
|
|
'queryWord': kw,
|
|
'cl': '2',
|
|
'lm': '-1',
|
|
'ie': 'utf-8',
|
|
'oe': 'utf-8',
|
|
'adpicid':'',
|
|
'st':'',
|
|
'z':'',
|
|
'ic':'',
|
|
'hd':'',
|
|
'latest':'',
|
|
'copyright':'',
|
|
'word': kw,
|
|
's':'',
|
|
'se':'',
|
|
'tab':'',
|
|
'width':'',
|
|
'height':'',
|
|
'face':'',
|
|
'istype':'',
|
|
'qc':'',
|
|
'nc':'',
|
|
'fr':'',
|
|
'expermode':'',
|
|
'force':'',
|
|
'cg': 'girl',
|
|
'pn': str(i),
|
|
'rn': '30',
|
|
'gsm':'',
|
|
'1600066985636':''
|
|
}
|
|
response = requests.get(url = url,headers = headers,params=params)
|
|
datas = response.json()
|
|
infos.append(datas)
|
|
except:
|
|
continue
|
|
return infos
|
|
# # print(datas['data'][0]['thumbURL'])
|
|
#
|
|
def down_loads(datas):
|
|
img_urls = []
|
|
for j in datas['data']:
|
|
try:
|
|
img_url = j['thumbURL']
|
|
img_urls.append(img_url)
|
|
except:
|
|
continue
|
|
|
|
|
|
for url in img_urls:
|
|
suffix = os.path.splitext(url)[1]
|
|
img_name = str(random.randint(0,100000)) + suffix
|
|
request.urlretrieve(url,r".\pic\\" + img_name)
|
|
print(f'{img_name}已经下载完成!!!')
|
|
|
|
|
|
def main():
|
|
kw = input('请输入你想下载的图片:')
|
|
po = Pool(10)
|
|
datas = parse(kw,20)
|
|
for data in datas:
|
|
po.apply_async(down_loads,args=(data,))
|
|
po.close()
|
|
po.join()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|