代码之家  ›  专栏  ›  技术社区  ›  Adder

HttpUnit-如何使用getTextBlocks

  •  1
  • Adder  · 技术社区  · 7 年前

    我想知道如何使用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 回复  |  直到 7 年前
    推荐文章