我正在使用Selenium从Surfline上提取当前的冲浪条件,但当我试图从“颤振-冲浪高度”类中提取冲浪高度时,会返回一个空字符串。
这就是Surfline html的样子。
<span class="quiver-surf-height">3-4<sup>FT</sup></span>这是我的密码。
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
surf = driver.find_element(By.CLASS_NAME, "quiver-surf-height").text
print (f"The contents of surf is: {surf}")发布于 2022-10-05 00:05:53
经过更多的实验,我无法找到一个解决方案,为什么Selenium不能从“颤栗-冲浪-高度”中检索数据。然而,通过对一个元素执行几个级别上的搜索,“抖动点-预测-总结_stat”,我能够将所有后续数据作为文本。
surf = driver.find_element(By.CLASS_NAME, "quiver-spot-forecast-summary__stat").text
print (f"The contents of surf is: {surf}")返回
The contents of surf is: Surf height
3-4ft
Waist to chest发布于 2022-10-05 09:37:21
尝试使用Xpath,右键单击HTML元素并复制Xpath并将其粘贴到下面的代码中。
driver.find_element(By.XPATH, "INSERT XPATH HERE")https://stackoverflow.com/questions/73954610
复制相似问题