使用Selenium刮取JavaHeavy网站返回无

2024-06-01 03:25:48 发布

您现在位置:Python中文网/ 问答频道 /正文

这里是新的编码员。一段时间以来,我一直在尝试使用Selenium在一个非常基于java的网站上刮取一段文本。不确定我做错了什么,这一点

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://explorer.helium.com/accounts/13pm9juR7WPjAf7EVWgq5EQAaRTppu2EE7ReuEL9jpkHQMJCjn9")

earnings = driver.find_elements_by_class_name('text-base text-gray-600 mb-1 tracking-tight w-full break-all')

print(earnings)

driver.quit()

试图刮取的元素的图像:

enter image description here

我正试图在这个容器中刮去那一美元,这样我最终可以在我正在构建的每日报告中使用它

我尝试过的每件事都没有结果。即使我试图从该元素中获取文本

这里是网站链接:https://explorer.helium.com/accounts/13pm9juR7WPjAf7EVWgq5EQAaRTppu2EE7ReuEL9jpkHQMJCjn9


Tags: texthttps文本com元素网站driverselenium
2条回答

您应该等待javascript加载、页面加载、元素加载。

_ = driver.Manage().Timeouts().ImplicitWait;

您可以创建条件,直到元素出现。

 ExpectedConditions ......  define selenium conditions

 //This is how we specify the condition to wait on.
 wait.until(ExpectedConditions.alertIsPresent());

您可以使用XPATH!美元坚挺

 /html/body/div[1]/div/article/div[2]/div/div[2]/div/div[2]/div[1]/div[2]/div[2]

FIREFOX XPATH FINDER

https://addons.mozilla.org/en-US/firefox/addon/xpath_finder/

您可以使用这个xpath

//*[@id="app"]/article/div[2]/div/div[2]/div/div[2]/div[3]/div[1]/div[1]/div[3]

相关问题 更多 >