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