1
我需要下載一個CSV文件,使用瀏覽器工作正常:python urllib2.openurl不能使用特定的URL(重定向)?
下面的代碼適用於任何其他文件(URL)(用完全合法的路徑),但上述網址是下載800字節的亂碼。
def getFile(self,URL):
proxy_support = urllib2.ProxyHandler({'http': 'http://proxy.REMOVED.com:8080/'})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
response = urllib2.urlopen(URL)
print response.geturl()
newfile = response.read()
output = open("testFile.csv",'wb')
output.write(newfile)
output.close()
適合我,沒有代理服務器。也許代理(緩存/訪問控制)麻煩。 – gimel 2010-03-24 17:34:49