我已经使用Python和Selenium编写了一些代码,用于从一个网站上抓取"Latitude"数据,例如"49°57'09"N (49.952500)",但不知何故,我却得到了TimeoutException异常。我无法理解自己的错误在哪里。如果您能提供任何帮助,我将不胜感激。
以下是我正在尝试的脚本:
以下是我正在尝试的脚本:
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()
driver.get("http://www.gcmap.com/airport/EDEF")
wait = WebDriverWait(driver, 10)
driver.switch_to_frame(0)
for item in wait.until(EC.presence_of_all_elements_located((By.XPATH, "//table[contains(@class,'vcard')]//td/abbr[@class='latitude']"))):
print(item.text)
driver.quit()
纬度所在的元素:
<td colspan="2" nowrap=""><abbr class="latitude" title="49.952500"></abbr>49°57'09"N (49.952500)</td>
这是我得到的错误信息:
80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
selenium
没有类似于bs4的.findParent
,所以这肯定是一个变通方法,尽管它似乎是做这件事情的最佳方式,你可以在这个w3schools页面中检查XPath的语法“解释”。 - Vinícius Figueiredo