title: Download file via javascript onclick using Python?
body: <p>On this page there is a button that reads <code>Download CSV</code>:
  <a href="http://www.nasdaqomxnordic.com/aktier/microsite?Instrument=CSE77855&amp;name=Pandora&amp;ISIN=DK0060252690" rel="nofollow noreferrer">http://www.nasdaqomxnordic.com/aktier/microsite?Instrument=CSE77855&amp;name=Pandora&amp;ISIN=DK0060252690</a></p>
  
  <p>How can I download the file using Python?</p>
  
  <p>The html of the page reads:</p>
  
  <pre><code>&lt;a class="floatRight exportTrades" id="exportIntradayTradesCSV"&gt;Download CSV&lt;/a&gt;
  
  &lt;script&gt;
  // #*
  
  var tradesForShare = {
      load: function () {
          var q = {
              "SubSystem": "Prices",
              "Action": "GetInstrument",
              "inst.an": "nm",
              "inst.e": "3",
              "Exchange": "NMF",
              "Instrument": webCore.getInstrument(),
              "cache": "skip",
              "app": location["pathname"],
              "datasource": "prod",
              "translationFile": "translation",
              "DefaultDecimals": false
          };
  
          $("#tradesForShareOutput").loading("/static/nordic/css/img/loading.gif");
          var nordicRTI = NordicRTI.getInstance();
          var url = window.webCore.getWebAPIURL("prod", "MarketData/GetMarketData", true);
          var tradesRTI = new RTIObject(url, q, function (data) {
              tradesForShare.parseData(data);
                         console.log(tradesRTI);
          });
          nordicRTI.addRTIObject(tradesRTI);
  
          if($("tradesForShareTable").has("tr.odd")) {
                       $('.exportTrades').removeClass('disabled');
                       $('.exportTrades.disabled').css("pointer-events","auto");
                  } else {
                       $('.exportTrades').addClass('disabled');
                       $('.exportTrades').css("pointer-events","none");
                  }
          /*webCore.getMarketData(q, function (data) {
              tradesForShare.parseData(data);
          }, true);*/
  
          //var url = window.webCore.getWebAPIURL("prod", "MarketData/GetMarketData", true);
          /*$.getJSON(url, q, function (data) {
              tradesForShare.parseData(data);
          });*/
          /*$.ajax({
              type: "get",
              url: url,
              data: q,
              dataType: "jsonp",
              cache: true,
              success: function (data) {
                  tradesForShare.parseData(data);
              },
              jsonp: "callback"
          });*/
  
          //setTimeout ( tradesForShare.load, 1000*30 );  // update every minute
      },
      parseData: function (data) {
          if(data.instruments != null) {
              $("#tradesForShareOutput").empty();
              var table = $("&lt;table&gt;&lt;/table&gt;").attr("id", "tradesForShareTable").addClass("tablesorter");
              var thead = $("&lt;thead&gt;&lt;/thead&gt;");
              var row = $("&lt;tr&gt;&lt;/tr&gt;");
              var kurs = $("&lt;th&gt;&lt;/th&gt;").text(webCore.getTranslationFor("trades", "p", data));// data.attributeTranslations.trades.p.trans[window.currentLanguage]);
              var vol = $("&lt;th&gt;&lt;/th&gt;").text(webCore.getTranslationFor("trades", "v", data));// data.attributeTranslations.trades.v.trans[window.currentLanguage]);
              var name = $("&lt;th&gt;&lt;/th&gt;").text(webCore.getTranslationFor("trades", "nm", data));// data.attributeTranslations.trades.nm.trans[window.currentLanguage]);
              var buyer = $("&lt;th&gt;&lt;/th&gt;").text(webCore.getTranslationFor("trades", "b", data));// data.attributeTranslations.trades.b.trans[window.currentLanguage]);
              var seller = $("&lt;th&gt;&lt;/th&gt;").text(webCore.getTranslationFor("trades", "s", data));// data.attributeTranslations.trades.s.trans[window.currentLanguage]);
              var time = $("&lt;th&gt;&lt;/th&gt;").text(webCore.getTranslationFor("trades", "t", data));// data.attributeTranslations.trades.t.trans[window.currentLanguage]);
              row.append(kurs).append(vol).append(name).append(buyer).append(seller).append(time);
              thead.append(row);
              var tbody = $("&lt;tbody&gt;&lt;/tbody&gt;");
              $.each(data.instruments[webCore.getInstrument().toLowerCase()].trades, function (k, v) {
                  row = $("&lt;tr&gt;&lt;/tr&gt;");
                  kurs = $("&lt;td&gt;&lt;/td&gt;").text(webCore.formatNumeric(v.values.p, 3));
                  vol = $("&lt;td&gt;&lt;/td&gt;").text(window.webCore.formatNumeric(v.values.v, 0));
                  name = $("&lt;td&gt;&lt;/td&gt;").text(v.values.nm);
                  buyer = $("&lt;td&gt;&lt;/td&gt;").text(v.values.b);
                  seller = $("&lt;td&gt;&lt;/td&gt;").text(v.values.s);
                  time = $("&lt;td&gt;&lt;/td&gt;").text(webCore.getTimeFromDateString(v.values.t));
                  row.append(kurs).append(vol).append(name).append(buyer).append(seller).append(time);
                  tbody.append(row);
              });
              table.append(thead).append(tbody);
              $("#tradesForShareOutput").append(table);
              $("#tradesForShareTable").tablesorter({widgets: ['zebra']});
          }
      },
      excel: function () {
          var instrument = null;
          instrument = window.webCore.getInstrument();
          var utc = new Date().toJSON().slice(0,10).replace(/-/g,'-');
          $("#xlsForm").attr( "action", webCore.getProxyURL("prod"));
          var xmlquery = webCore.createQuery( Utils.Constants.marketAction.getTrades, {}, {
              t__a: "1,2,5,10,7,8,18",
                           FromDate : utc,
                           Instrument : instrument,
              ext_contenttype : "application/vnd.ms-excel",
              ext_contenttypefilename : "share_export.xls",
              ext_xslt:"t_table_simple.xsl",
              ext_xslt_lang: currentLanguage,
                          showall: "1"
          });
          console.log(xmlquery);
          $("#xmlquery").val( xmlquery );
          $("#xlsForm").submit();
      }
  };
  
  $(function () {
      tradesForShare.load();
  $("#exportIntradayTradesCSV").on({
          click: function (e) {
                  tradesForShare.excel();
              //window.webCore.exportTableToCSVClickEvent($("#exportIntradayTradesCSV"), $("#tradesForShareOutput"), '_' + window.webCore.getInstrument() + '.csv');
          }
      });
  });
  
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p>I tried using <code>Inspect</code> in Google Chrome and clicking on <code>Event Listeners</code>.</p>
  
  <p>I got the following output, when clicking the button:</p>
  
  <pre><code>&lt;post&gt;
  &lt;param name="SubSystem" value="Prices"/&gt;
  &lt;param name="Action" value="GetTrades"/&gt;
  &lt;param name="Exchange" value="NMF"/&gt;
  &lt;param name="t__a" value="1,2,5,10,7,8,18"/&gt;
  &lt;param name="FromDate" value="2018-08-29"/&gt;
  &lt;param name="Instrument" value="CSE77855"/&gt;
  &lt;param name="ext_contenttype" value="application/vnd.ms-excel"/&gt;
  &lt;param name="ext_contenttypefilename" value="share_export.xls"/&gt;
  &lt;param name="ext_xslt" value="/nordicV3/t_table_simple.xsl"/&gt;
  &lt;param name="ext_xslt_lang" value="en"/&gt;
  &lt;param name="showall" value="1"/&gt;
  &lt;param name="app" value="/aktier/microsite"/&gt;
  &lt;/post&gt;
  </code></pre>
  
  <p>So I thought I could do something similar to the following, but it doesn't work; see output further below.</p>
  
  <pre><code>import requests
  
  url = 'http://www.nasdaqomxnordic.com/WebAPI/api/MarketData/GetMarketData'
  params = {
  "SubSystem": "Prices",
  "Action": "GetTrades",
  "Exchange": "NMF",
  "t__a": "1,2,5,10,7,8,18",
  "FromDate": "2018-08-29",
  "Instrument": "CSE77855",
  "ext_contenttype": "application/vnd.ms-excel",
  "ext_contenttypefilename": "share_export.xls",
  "ext_xslt": "/nordicV3/t_table_simple.xsl",
  "ext_xslt_lang": "en",
  "showall": "1",
  "app": "/aktier/microsite",
  }
  
  r = requests.get(url, params=params)
  
  print(r.json())
  </code></pre>
  
  <p>I get the following output:</p>
  
  <pre><code>{'linkCall': 'SubSystem=Prices&amp;Action=GetTrades&amp;Exchange=NMF&amp;t.a=1&amp;t.a=2&amp;t.a=5&amp;t.a=10&amp;t.a=7&amp;t.a=8&amp;t.a=18&amp;FromDate=2018-08-29&amp;Instrument=CSE77855&amp;ext_contenttype=application%2fvnd.ms-excel&amp;ext_contenttypefilename=share_export.xls&amp;ext_xslt=%2fnordicV3%2ft_table_simple.xsl&amp;ext_xslt_lang=en&amp;showall=1&amp;app=%2faktier%2fmicrosite', 'instruments': None, 'derivatives': None, 'warrants': None, 'attributeTranslations': {}, 'message': None, 'success': False}
  </code></pre>
  
  <p>If possible I would like to avoid <code>Selenium</code>.</p>