我一直在尝试下载自动化股票市场的链接,我的代码会运行,但zip文件无法下载。
import urllib
import urllib2
import requests
url ='https://www.nseindia.com/content/historical/EQUITIES/2016/DEC/cm29DEC2016bhav.csv.zip'
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'}
print "downloading with urllib"
urllib.urlretrieve(url, "code.zip")
print "downloading with urllib2"
req = urllib2.Request(url, headers=hdr)
f = urllib2.urlopen(req)
data = f.read()
with open("code2.zip", "wb") as code:
code.write(data)
print "downloading with requests"
r = requests.get(url)
with open("code3.zip", "wb") as code:
code.write(r.content)
我希望将zip文件下载到C:\ Users \ User \ Downloads文件夹中,以便我可以自动执行解压缩过程,然后将该csv文件保存到硬盘中。任何帮助,将不胜感激。谢谢。
答案 0 :(得分:0)
该文件正在下载到当前工作目录,可能是vec4
。去检查那里。尝试将其下载到Vehiclelist.Where(q => q.Trucks=="Y" || q.Cars=="Y" || q.Utility=="Y");
文件夹:
C:\Python[Version]