各位專家好,
出于興趣愛好,本人寫了一個腳本自動從公司網頁上自動下載分析結果。
在下載時,出現以下問題:
1. 利用find_elements_by_tag_name找到了相應的控制元件(名字為‘ele’);

2. 呼叫如下代碼:
print('before ele click')
ele.click()
print('after ele click')
3. 網頁上彈出了下載對話框,但是PYTHON 代碼卻再也沒有執行,停止在ele.click();

4. 從python的控制臺上也可以看到print('after ele click')沒有被執行;

請各位專家幫忙看下怎么回事。
另,各位大俠是否知道對后續彈出的下載對話框,如何實作另存為?
謝謝!
uj5u.com熱心網友回復:
看截屏貌似是IE瀏覽器?換chrome吧
思路是初始化webdriver的時候,用擴展引數把瀏覽器的下載確認關閉掉
options.add_experimental_option("prefs", {
"download.prompt_for_download": False,
})
uj5u.com熱心網友回復:
兄弟是個高手,一眼看出是IE. 可是公司的這個網頁就是只能用IE......您知道這個為什么掛住了嗎?怎么讓后面的程式繼續呢?
謝謝!
uj5u.com熱心網友回復:
我查了一下檔案,IExplorer的driver好像沒有提供可以禁止下載提示的啟動引數換個思路,可以嘗試直接在作業系統級別或者IE瀏覽器自己的設定里面去關閉下載提示,
我沒有window環境,所以沒法自己嘗試,你可以參考一下這篇文章:https://superuser.com/questions/246553/how-to-disable-file-download-popup-in-internet-explorer
上面提供了3種嘗試方法,我摘出來
# Solution 1
Open Internet Explorer > Tools > Internet Options > Advanced > Security :
Clear the 'Do not save encrypted pages to disk'.
Clear the 'Do not save encrypted pages to disk'
# Solution 2
Open Internet Explorer > Tools > Internet Options > Security > Custom level > Download :
Select Disable for 'Automatic prompting for file download'.
Repeat this for all 4 zones.
Disable automatic prompting for file download
# Solution 3
Open My Computer > Tools > Folder Options > File Types > PDF > Advanced :
Clear the 'Confirm open after download'
uj5u.com熱心網友回復:
非常感謝你的熱心。
就如你所說,換了個思路。我不用PYTHON的控制元件了,而改用了控制滑鼠鍵盤來實作下載。
我的關鍵問題還是.click()執行后掛死。不知道是不是PYTHON本身的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/90928.html
上一篇:求解
