获取页面的可见文本 [英] Get visible text of page

查看:96
本文介绍了获取页面的可见文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在没有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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆