【问题标题】:Selenium, Python (raise TimeoutException(message, screen, stacktrace) TimeoutException)Selenium, Python (引发 TimeoutException(message, screen, stacktrace) TimeoutException)
【发布时间】:2023-04-03 21:20:02
【问题描述】:

from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 

url = "https://www.electionreturns.pa.gov/General/OfficeResults?OfficeID=13&ElectionID=undefined&ElectionType=undefined&IsActive=1" 

options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")

driver = webdriver.Chrome(r"...\chromedriver.exe", options = options)
driver.get(url)


try: 
    element = WebDriverWait(driver,20).until(
            EC.visibility_of_element_located((By.XPATH, "/html/body/script[15]"))
            )

finally: 
    driver.quit()

这方面很新,但我似乎无法在 Selenium 文档和 StackO 之间弄清楚这一点。

这引发了:

raise TimeoutException(message, screen, stacktrace)

TimeoutException

再次,这是新的。我相当确定我要访问的 java 脚本是 src="/Scripts/AppScripts/GeneralController.js" (?v=1.2)。其中有/html/body/script[15] 的xpath。但是,我的访问方法可能是错误本身。

感谢任何见解。谢谢,C。

【问题讨论】:

  • 为什么要用src="/Scripts/AppScripts/GeneralController.js?v=1.2访问元素?你的下一步行动是什么?
  • 它生成的 HTML 会吐出选举结果,我想将其读入 BS4 以用于选举网络爬虫。

标签:
python
selenium
xpath
webdriver
timeoutexception