2012-04-24 97 views
0

我曾联系被称为“点击下载”的网页和HTML表单上是下载从链接Excel文件在python

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

,当我在“单击此处下载”一个Excel点击文件被下载,其实我需要找到链接的网址来下载excel文件。

,我不得不用下面

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'); 
} 

任何人都可以请清除此数据的代码JavaScript函数,在此先感谢

+0

-1“请给我的代码” - 没有足够的上下文来给他们太多。 – Kimvais 2012-04-24 09:27:06

+0

感谢您的回复,我上面给出了我的代码 – 2012-04-24 10:36:26

回答

3

当你点击该按钮,一个JavaScript函数被调用,并且可能重定向到该文件。

为了能够用python下载文件,你需要自己找到链接(如果你总是下载相同的文件),然后使用urllib。为此,您可以阅读JavaScript代码。

或者你需要使用一些浏览器自动化工具(通过蟒蛇例如),如硒:http://seleniumhq.org/