HttpUnit - 如何使用getTextBlocks

时间:2018-06-12 12:19:29

标签: java http-unit

我想知道如何使用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>

0 个答案:

没有答案
相关问题