我想知道如何使用 http 单元访问网页中的所有文本。我遇到的问题是getTextBlocks
似乎只返回h1
..h6
标签中的文本。我想找到下面 HTML 片段中包含的文本“Support LS”。请原谅我的简短问题,但谷歌搜索httpunit getTextBlocks
不会返回许多有用的匹配项。我想知道是否必须递归地降低文本块,因为每个文本块似乎都有一个getTextBlocks
- 方法。
TextBlock[] texts;
try {
texts = actualResponse.getTextBlocks();
} catch (SAXException e) {
e.printStackTrace();
return e.toString();
}
errorMessage = "Did not find needle " + webService.getWebServiceNeedle();
for(int i = 0; i<texts.length; ++i) {
TextBlock tb = texts[i];
if(debugMode) {
logger.debug("Web Check " + webService.getWebServiceName() + " Text =" + tb.getText());
}
if(tb.getText().indexOf(webService.getWebServiceNeedle()) >= 0) {
logger.info("Found needle" + webService.getWebServiceNeedle());
errorMessage = null;
break;
}
}
<!-- <body> -->
<header class="clsHead">
<div>
<a href="#wrapper" id="menu-toggle" class="glyphicons glyphicons-show-lines clsMenuMain"></a>
</div>
<div>
<span class="clsHeadFont"> 2.0 </span>
</div>
<div>
<marquee id="flashMessage" style="position: absolute;bottom: 18px;left:240px;" class="span8" scrollamount="4"></marquee>
</div>
<div class="CLSuserloginadmin">
<!-- <span ><div style="float:right">
</div></span> -->
<span class="clsHeadFont1">Welcome, Support LS</span> <span
class="clsHeadFont1 clsHeadLogPad"> | </span> <a href="logout">Logout </a>
<a class="dropdown-toggle" data-toggle="dropdown"><img
class=""
src="/rator-monitoring/resources/img/setting.png"
id="lodindb"
style="width: 28px; margin-top: -5px; padding-left: 11px;"></a>
<ul class="dropdown-menu" role="menu">
<li class="version">About</li>
<li class="preferences">User Preferences</li>
</ul>
</div>
</header>