自己改了一下要下载的url,一个网页,一个exe,一个PDF
import requests import multiprocessing def download_file(url): local_filename = url.split('/')[-1] with requests.get(url, stream=True) as r: r.raise_for_status() with open(local_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=8192): if chunk: f.write(chunk) return local_filename if __name__ == '__main__': urls = ['https://www.cnblogs.com/pu369/p/17221436.html', 'http://www.zs.gov.cn/attachment/0/402/402310/1931387.pdf', 'https://mksoftcdnhp.mydown.com/641c0606/c8d7945f45ef80c0f98df9ab11241922/uploadsoft/newsoft/OCR_ocr-tjxz.exe'] with multiprocessing.Pool(processes=3) as pool: result = pool.map(download_file, urls) print(result)
标签:__,map,示例,url,chunk,filename,local,pool From: https://www.cnblogs.com/pu369/p/17247709.html