我可以用下面的代码过滤数据,但导出到Excel不起作用。我请求您的帮助,如何改进我下面的代码片段,以指示Python等待数据完全加载,然后将excel文件下载到所需的文件夹中。在
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
driver = webdriver.Chrome("C:\Python27\Scripts\chromedriver.exe")
driver.get("https://etrakit.friscotexas.gov/Search/permit.aspx")
number_option = driver.find_element_by_id("cplMain_btnSearch")
number_option.click()
delay = 3
try:
WebDriverWait(driver, delay).until(EC.presence_of_element_located(driver.find_element_by_id("cplMain_btnSearch")))
print "Page is ready!"
except TimeoutException:
print "Loading took too much time!"
search_button = driver.find_element_by_id("cplMain_btnExportToExcel")
search_button.click()
options.add_argument("download.default_directory=C:\Users\Patrick\Desktop\Programming\R Files")
driver = webdriver.Chrome(chrome_options=options)
driver.close()
错误:
^{pr2}$
试着换掉这个
用这个
^{pr2}$你的问题是:
等待的重点是不要尝试自己寻找元素,因为它可能还不存在!在本例中,您碰巧找到了它,错误是因为您使用了
^{pr2}$presence_of_element_located
。以下是您需要做的:参见文档:http://selenium-python.readthedocs.io/waits.html#explicit-waits
相关问题 更多 >
编程相关推荐