使用python 下载_使用python下载大量文件
有沒有一種很好的方法來使用
python大量下載大量文件?此代碼足夠快速下載大約100個左右的文件.但我需要下載300,000個文件.顯然它們都是非常小的文件(或者我不會下載300,000個:))所以真正的瓶頸似乎是這個循環.有人有想法嗎?也許使用MPI或線程?
我只需要和瓶頸一起生活嗎?或者有更快的方式,甚至可能沒有使用python?
(為了完整起見,我包含了代碼的完整開頭)
from __future__ import division
import pandas as pd
import numpy as np
import urllib2
import os
import linecache
#we start with a huge file of urls
data= pd.read_csv("edgar.csv")
datatemp2=data[data['form'].str.contains("14A")]
datatemp3=data[data['form'].str.contains("14C")]
#data2 is the cut-down file
data2=datatemp2.append(datatemp3)
flist=np.array(data2['filename'])
print len(flist)
print flist
###below we have a script to download all of the files in the data2 database
###here you will need to create a new directory named edgar14A14C in your CWD
original=os.getcwd().copy()
os.chdir(str(os.getcwd())+str('/edgar14A14C'))
for i in xrange(len(flist)):
url = "ftp://ftp.sec.gov/"+str(flist[i])
file_name = str(url.split('/')[-1])
u = urllib2.urlopen(url)
f = open(file_name, 'wb')
f.write(u.read())
f.close()
print i
總結
以上是生活随笔為你收集整理的使用python 下载_使用python下载大量文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 谷歌版ChatGPT翻车 员工狠批CEO
- 下一篇: 网传华为将全面主导AITO汽车 官方回应