Python code to download a webpage using JavaScript
<p>Im trying to download share data from a stock exchange using python. The problem is that there is no direct download link, but rather a javascript to export the data.</p>

<p>The data page url:  </p>

<pre><code>http://tase.co.il/TASE/Templates/Company/CompanyHistory.aspx?NRMODE=Published&amp;NRORIGINALURL=%2fTASEEng%2fGeneral%2fCompany%2fcompanyHistoryData.htm%3fcompanyID%3d001216%26ShareID%3d01091248%26subDataType%3d0%26&amp;NRNODEGUID={045D6005-5C86-4A8E-ADD4-C151A77EC14B}&amp;NRCACHEHINT=Guest&amp;shareID=01820083&amp;companyID=000182&amp;subDataType=0
</code></pre>

<p>When I open the data page in a browser and then the download page, it works like a charm.
When I just open the download page, it doen't download anything. I guess this is because the data page injects the actual data to the variables Columns, Titles etc.</p>

<p>I've tried to mimic this behaviour in a python script, but without success.</p>

<pre><code>def download_CSV (shareID, compID):
 data_url ="http://tase.co.il/TASE/Templates/Company/CompanyHistory.aspx?NRMODE=Published&amp;NRORIGINALURL=%2fTASEEng%2fGeneral%2fCompany%2fcompanyHistoryData.htm%3fsubDataType%3d0%26shareID%3d00759019&amp;NRNODEGUID={045D6005-5C86-4A8E-ADD4-C151A77EC14B}&amp;NRCACHEHINT=Guest&amp;shareID="+shareID+"&amp;companyID="+compID+"&amp;subDataType=0"  
 import urllib2
 response = urllib2.urlopen(data_url)
 html = response.read()

 down_url ="http://tase.co.il/TASE/Pages/Export.aspx?tbl=0&amp;Columns=AddColColumnsHistory&amp;Titles=AddColTitlesHistory&amp;sn=dsHistory&amp;enumTblType=GridHistorydaily&amp;ExportType=3"  
 import urllib
 urllib.urlretrieve (down_url, "test.csv")
</code></pre>

<p>Thanks a lot</p>
