【问题标题】:How to parse Label section in Html web page via jsoup in android如何通过android中的jsoup解析Html网页中的标签部分
【发布时间】:2017-02-28 17:19:28
【问题描述】:

我正在开发 android 应用程序和 html 新手,我在使用 android 中的 jsoup 解析 html 网页的特定元素时面临障碍。如果有人可以指导我 我是软件开发领域的新手

下面是我要解析的部分

</head>
   <body onload="update_content();">
<div class="homeBox">
<br>
<div class="brdr1"> 
    <h2 id="h2Internet">LTE</h2>
</div>
    <hr>
    <div class="boxInner brdr2"> 
    <a>
    <div style="display: block;" id="Cellular">
    <span class="heading1" id="h3IntrenetConnection">LTE Status</span>
    <strong id="pSimStatus">Connected Status:</strong><br>
    <label id="lSIMStatusValue"></label>
    </div>
    <br>
    <div style="display: none;" id="Internet_DIV">
        <strong id="pDashCurConnTime">Connection Time:</strong>
        <label id="lDashCurConnValue">00:02:30:40</label>
        <br><br>
            <div id="divEngineerInform">
                <strong id="operatingMode">Operating Mode:</strong>
                <label id="LoperMode">TDD</label>
                <br><br>  
                <strong id="pDashEngineerInform_bandTag">Operating Band:</strong>
                <label id="pDashEngineerInform_bandValue" style="margin-left:5px;">40</label>
                <br><br>
                <strong id="pDashEngineerInform_bandwidthTag">Bandwidth:</strong>
                <label id="pDashEngineerInform_bandwidthValue" style="margin-left:5px;">20MHz</label>
                <br><br>
                <strong id="pDashEngineerInform_earfcnTag">EARFCN:</strong>
                <label id="pDashEngineerInform_earfcnValue" style="margin-left:5px;">38457</label>
                <br><br>
                <strong id="pDashEngineerInform_phycellTag">Physical Cell ID:</strong>
                <label id="pDashEngineerInform_phycellValue" style="margin-left:5px;">**9**</label>
                <br><br>
                <strong id="pDashAutoApn_plmnTag">PLMN:</strong>
                <label id="pDashAutoApn_plmnValue" style="margin-left:5px;margin-bottom:5px;">**405567**</label>
                <br><br>
                <strong id="pDashAutoApn_LteApnTag">APN in Use:</strong>
                <label id="pDashAutoApn_LteApnValue" style="margin-left:5px;">**xyyuet**</label>
                <br><br>

我想解析 LABEL 部分中的元素(在双星之间),但我不知道。

【问题讨论】:

    标签: android html parsing jsoup


    【解决方案1】:

    等了很久还是没有答案,所以我自己研究了一下,找到了答案,不过这可能很简单或幼稚,但我想分享答案。

    当我问到如何解析标签标签中的特定元素时,尽管它的 id 具有值所以“string s= element.val();”不行,下面是代码sn-p

    <strong id="pDashAutoApn_LteApnTag">APN in Use:</strong>
    <label id="pDashAutoApn_LteApnValue" style="margin-left:5px;">**xyyuet**</label>
    

    所以解决办法是

    htmlDocument = Jsoup.connect(htmlPageUrl).get();
    Element element= htmlDocument.getElementById("lDashCurConnValue");
    htmlContentInStringFormat=element.text();
    

    我只是使用“element.text()”检索标签中的文本。

    【讨论】:

      猜你喜欢
      • 2015-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-01
      • 2013-09-21
      • 2015-07-20
      • 1970-01-01
      相关资源
      最近更新 更多