简体   繁体   中英

Downloading an excel file from a link in python

I had link called "Click here to download" on an a page and its HTML form is

<span id="spnDwnRec">
<a class="spnRecordText" onclick="CallExcelFunction()" href="#"> Click here to download all records.</a>
</span>

When i clicked on "Click here to download" an excel file is downloaded, Actually i need to find the url of the link to download excel file.

And i had the javascript function with the code below

function CallExcelFunction() {
    var hidInd = document.getElementById('hidInd');
    var hidFromDate = document.getElementById('hidFromDate');
    var hidToDate = document.getElementById('hidToDate');
    var hidDMY = document.getElementById('hidDMY');
    window.open('indices_main_excel.aspx?ind=' + hidInd.value + '&fromDate=' + hidFromDate.value + '&toDate=' + hidToDate.value + '&DMY=' + hidDMY.value, '_blank',
'toolbar=yes,location=no, directories=no, status=no, menubar=yes,scrollbars=yes, resizable=yes ,copyhistory=no, width=800, height=600');
}

can anyone please clear this data, thanks in advance

When you click on that button, a javascript function is invoked, and that probably redirects to the file.

To be able to download the file with python, you either need to find the link on your own (if you are always downloading the same file), and then use urllib. For that, you could read the javascript code.

Or you need to use some browser automation tool (through python for example), like selenium: http://seleniumhq.org/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM