我对Python完全陌生,我想通过向服务器发送请求来下载文件。当我在浏览器中输入它时,我看到CSV文件已下载,但当我尝试发送get请求时,它不返回任何内容。例如:
import urllib2
response = urllib2.urlopen('https://publicwww.com/websites/%22google.com%22/?export=csv')
data = response.read()
print 'data: ', data
它没有显示任何内容,我该如何处理?当我在网上搜索时,所有的问题都是关于如何发送get请求的。我可以发送get请求,但我不知道如何下载该文件,因为它不在请求的响应中。
我不知道如何找到解决方案。
发布于 2018-03-05 23:26:11
您可以使用urlretrieve
下载该文件
示例:
u = "https://publicwww.com/websites/%22google.com%22/?export=csv"
import urllib
urllib.request.urlretrieve (u, "Ktest.csv")
发布于 2018-03-05 23:30:25
您还可以使用python中的request模块下载文件。
import shutil
import requests
url = "https://publicwww.com/websites/%22google.com%22/?export=csv"
response = requests.get(url, stream=True)
with open('file.csv', 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
del response
发布于 2018-03-05 23:25:14
import os
os.system("wget https://publicwww.com/websites/%22google.com%22/?export=csv")
你可以尝试wget,如果你有的话。
https://stackoverflow.com/questions/49113616
复制相似问题