with open(imgFile, 'wb+')as f: f.write(img_ret.content)
defdownloadMain(num): pool = ThreadPoolExecutor(12)
all_task = [] for i in range(num): print('Crawling images on page %s' % (i + 1)) ret = requests.get('https://bing.ioliu.cn/?p=%d' % (i + 1), headers={'User-Agent': UserAgent().random})
for img in img_list: img_url = img.get('src').replace('640x480', '1920x1080')
all_task.append(pool.submit(download, img_url)) wait(all_task) if __name__ == '__main__': print('Existing pictures will be skipped.') pictureNum = input('How many pages to download? 12 per page. (default: 135): ') or'135' num = eval(pictureNum) downloadMain(num) print('Over!')