我试图使用python从股票交易所下载股票数据。问题是没有直接下载链接,而是导出数据的javascript。
数据页面网址:
http://tase.co.il/TASE/Templates/Company/CompanyHistory.aspx?NRMODE=Published&NRORIGINALURL=%2fTASEEng%2fGeneral%2fCompany%2fcompanyHistoryData.htm%3fcompanyID%3d001216%26ShareID%3d01091248%26subDataType%3d0%26&NRNODEGUID={045D6005-5C86-4A8E-ADD4-C151A77EC14B}&NRCACHEHINT=Guest&shareID=01820083&companyID=000182&subDataType=0
当我在浏览器中打开数据页面然后下载页面时,它就像一个魅力。 当我打开下载页面时,它不会下载任何内容。我想这是因为数据页面将实际数据注入变量Columns,Titles等。
我试图在python脚本中模仿这种行为,但没有成功。
def download_CSV (shareID, compID):
data_url ="http://tase.co.il/TASE/Templates/Company/CompanyHistory.aspx?NRMODE=Published&NRORIGINALURL=%2fTASEEng%2fGeneral%2fCompany%2fcompanyHistoryData.htm%3fsubDataType%3d0%26shareID%3d00759019&NRNODEGUID={045D6005-5C86-4A8E-ADD4-C151A77EC14B}&NRCACHEHINT=Guest&shareID="+shareID+"&companyID="+compID+"&subDataType=0"
import urllib2
response = urllib2.urlopen(data_url)
html = response.read()
down_url ="http://tase.co.il/TASE/Pages/Export.aspx?tbl=0&Columns=AddColColumnsHistory&Titles=AddColTitlesHistory&sn=dsHistory&enumTblType=GridHistorydaily&ExportType=3"
import urllib
urllib.urlretrieve (down_url, "test.csv")
非常感谢