【发布时间】:2018-03-30 20:33:42
【问题描述】:
我已经用 selenium 在 python 中编写了一个脚本来单击网页中的某个链接以下载 excel 文件。但是,当我执行我的脚本时,它会抛出 timeout 异常。我怎样才能让它工作?任何帮助将不胜感激。
网站链接:webpage
我尝试过的脚本:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)
driver.get('replace_with_above_link')
item = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".hasmore #dlink")))
item.click()
driver.quit()
包含下拉选项的 HTML 元素:
<li class="hasmore drophover"><span>Share & more</span><div><ul><li><button class="tooltip" tip="Use a customizable report creator that can<br>output HTML, CSV, or a shareable link." id="share_on_ajax_result_table">Modify & Share Table</button></li><li><button class="tooltip" tip="Get a bit of widget code to emed this table on your site">Embed this Table</button></li><li><button class="tooltip" tip="Convert the table below to comma-separated values<br>suitable for use with excel">Get as Excel Workbook (experimental)</button><a id="dlink" style="display: none;"></a></li><li><button class="tooltip" tip="Export table as <br>suitable for use with excel">Get table as CSV (for Excel)</button></li><li><button class="tooltip" tip="">Strip Mobile Formatting</button></li><li><a id="a_ajax_result_table" name="ajax_result_table" href="#ajax_result_table::none">Copy Link to Table to Clipboard</a></li><li><button class="tooltip" tip="">About Sharing Tools</button></li><li><button class="tooltip" tip=""><a href="https://www.youtube.com/watch?v=MWapXbaWs_U&feature=youtu.be" target="_blank">Video: SR Sharing Tools & How-to</a></button></li><li><button class="tooltip" tip=""><a href="https://www.youtube.com/watch?v=JkDLV0roT14&feature=youtu.be" target="_blank">Video: Stats Table Tips & Tricks</a></button></li></ul></div></li>
【问题讨论】:
-
您是否尝试过先将光标移到“Share&more”元素上?
-
是的。我什至首先点击了
share&more链接,发现它工作正常。当我尝试点击上面提到的链接时出现问题。 -
链接实际上会导致文件下载和另存为对话框。为 Chrome 设置适当的自动下载选项(例如stackoverflow.com/questions/49053624/…)
-
@SiKing,我查看了您的个人资料,看看您是否总是将以前提出的不同问题标记为重复?答案是不。当你看到你可以解决它们时,你会尝试解决它们。但是,请查看this link。那是你最新的回复。您认为链接的问题是独一无二的吗?您试图解决这个问题,因为它很容易,但是当您遇到任何像我在这里发布的帖子时,您将其标记为重复。开什么玩笑!!!!!!
标签: python python-3.x selenium selenium-webdriver web-scraping