"""import os, multiprocessing import urllib3, certifi import pandas as pd import numpy as np def DownloadImage(key_url): try: (key, url, out_dir) = key_url.values[0] filename = os.path.join(out_dir, '%s.jpg' % key) image_data = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where()).request('GET', url).data f = open(filename,"wb") f.write(image_data) f.close except: print('Warning: Could not download image', key_url.values[0]) return def Run(key_url_list): if not os.path.exists(key_url_list['out_dir'][0]): os.mkdir(key_url_list['out_dir'][0]) p = multiprocessing.Pool(multiprocessing.cpu_count()) p.map(DownloadImage, np.array_split(key_url_list, len(key_url_list))) p.close(); p.join() if __name__ == '__main__': col = ['id','url','out_dir'] train = pd.read_csv('../input/train.csv')[:2] test = pd.read_csv('../input/test.csv')[:2] train['out_dir'] = 'train_out/' test['out_dir'] = 'test_out/' Run(train[col]) Run(test[col]) """ print("Happy Kaggling :)")
多线程下载图片
最新推荐文章于 2024-07-12 16:39:39 发布