获取页面的可见文本 [英] Get visible text of page
问题描述
如何在没有HTML标签的情况下使用selenium webdriver获取网页的可见文本部分?
How do I get the visible text portion of a web page with selenium webdriver without the HTML tags?
我需要与函数HtmlPage.asText()相当的东西来自Htmlunit。
I need something equivalent to the function HtmlPage.asText() from Htmlunit.
使用函数WebDriver.getSource获取文本并使用jsoup解析它是不够的,因为页面中可能存在隐藏元素(通过外部CSS) )我对他们不感兴趣。
It is not enough to take the text with the function WebDriver.getSource and parse it with jsoup because there could be in the page hidden elements (by external CSS) which I am not interested in them.
推荐答案
做 By.tagName(body)
(或选择顶部元素的其他选择器),然后对该元素执行 getText()
将返回所有可见文本。
Doing By.tagName("body")
(or some other selector to select the top element), then performing getText()
on that element will return all of the visible text.
这篇关于获取页面的可见文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!