【问题标题】:Selecting 1MYR = 15.55 INR using Jsoup使用 Jsoup 选择 1MYR = 15.55 INR
【发布时间】:2015-12-07 19:25:20
【问题描述】:

请帮助我使用 Jsoup 选择 1MYR = 15.55 INR。

<div style="position:relative;width:995px;height:25px;overflow:hidden">
   <div style="position:absolute;width:995px;height:25px;background-color:#ffffff" onmouseover="copyspeed=pausespeed" onmouseout="copyspeed=marqueespeed">
      <div id="iemarquee" style="position: absolute; left: 1359px; top: 3px; display: inline;">
         <div class="LBLBlack11">
           <b><font size="2">1 MYR = <font color="red">18.52 BDT</font>&nbsp;
            <img src="images/countryImages/Bangladesh.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">15.55 INR</font>&nbsp;
            <img src="images/countryImages/India.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">3,185.11 IDR</font>&nbsp;
            <img src="images/countryImages/Indonesia.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">304.00 MMK</font>&nbsp;
            <img src="images/countryImages/myanmar.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">24.95 NPR</font>&nbsp;
            <img src="images/countryImages/Nepal.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">24.65 PKR</font>&nbsp;
            <img src="images/countryImages/PAKISTAN.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">11.10 PHP</font>&nbsp;
            <img src="images/countryImages/Philippines.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">0.32 SGD</font>&nbsp;
            <img src="images/countryImages/Singapore.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">33.40 LKR</font>&nbsp;
            <img src="images/countryImages/SriLanka.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>
           </b>
         </div>
      </div>
      <div id="iemarquee2" style="position: absolute; left: -307px; top: 3px; display: inline;">
         <div class="LBLBlack11">
          <b><font size="2">1 MYR = <font color="red">18.52 BDT</font>&nbsp;
           <img src="images/countryImages/Bangladesh.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">15.55 INR</font>&nbsp;
           <img src="images/countryImages/India.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">3,185.11 IDR</font>&nbsp;
           <img src="images/countryImages/Indonesia.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">304.00 MMK</font>&nbsp;
           <img src="images/countryImages/myanmar.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">24.95 NPR</font>&nbsp;
           <img src="images/countryImages/Nepal.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">24.65 PKR</font>&nbsp;
           <img src="images/countryImages/PAKISTAN.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">11.10 PHP</font>&nbsp;
           <img src="images/countryImages/Philippines.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">0.32 SGD</font>&nbsp;
           <img src="images/countryImages/Singapore.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 MYR = <font color="red">33.40 LKR</font>&nbsp;
           <img src="images/countryImages/SriLanka.png" width="16" height="11">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>
         </b>
        </div>
      </div>
   </div>
</div>

【问题讨论】:

  • 因为您没有展示或解释您尝试过的内容。这看起来很像:“这是我的问题,现在为我解决!”
  • 您可以查找图片名称 ex.:Bangladesh.png

标签: html jsoup


【解决方案1】:

您可以通过简单的选择来完成:

String yourHtml = "...";
Document document = Jsoup.parse(yourHtml);
Element parent = document.select(".LBLBlack11 > b > font").first();
List<Node> nodes = parent.childNodes();
Node node4 = nodes.get(4);
Node node5 = nodes.get(5);
String result = "";
if(node4 instanceof TextNode){
    result += ((TextNode) node4).text().replace("\u00a0", ""); //Remove spaces
}

if(node5 instanceof Element){
    result += ((Element) node5).text();
}
System.out.println("Result: " + result);

为了删除空格,我使用了this solution

【讨论】:

    猜你喜欢
    • 2013-11-25
    • 2011-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-03
    • 2016-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多