我可以使用下面的代碼過濾數據,但導出到Excel不起作用。我請求你如何改進我的代碼片段以指導Python等待數據完全加載,然後將excel文件下載到所需的文件夾。如何判斷Python等待Selenium?
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()
的錯誤:
Traceback (most recent call last):
File "C:\Users\Patrick\Desktop\Programming\aspxscraping.py", line 14, in <module>
WebDriverWait(driver, delay).until(EC.presence_of_element_located(driver.find_element_by_id("cplMain_btnSearch")))
File "C:\Python27\lib\site-packages\selenium\webdriver\support\wait.py", line 71, in until
value = method(self._driver)
File "C:\Python27\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 63, in __call__
return _find_element(driver, self.locator)
File "C:\Python27\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 328, in _find_element
return driver.find_element(*by)
TypeError: find_element() argument after * must be a sequence, not WebElement
感謝安德森,對於代碼工作。現在,它顯示了Search.Button 回溯一個錯誤(最新最後調用): 文件 「C:\用戶\ aqureshi \桌面\程序\ aspxscraping.py」 22行,在 search_button.click() –
將完整的例外日誌添加到您的問題和用於搜索按鈕的「HTML」代碼 – Andersson