请帮我用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>
<img src="images/countryImages/Bangladesh.png" width="16" height="11"> 1 MYR = <font color="red">15.55 INR</font>
<img src="images/countryImages/India.png" width="16" height="11"> 1 MYR = <font color="red">3,185.11 IDR</font>
<img src="images/countryImages/Indonesia.png" width="16" height="11"> 1 MYR = <font color="red">304.00 MMK</font>
<img src="images/countryImages/myanmar.png" width="16" height="11"> 1 MYR = <font color="red">24.95 NPR</font>
<img src="images/countryImages/Nepal.png" width="16" height="11"> 1 MYR = <font color="red">24.65 PKR</font>
<img src="images/countryImages/PAKISTAN.png" width="16" height="11"> 1 MYR = <font color="red">11.10 PHP</font>
<img src="images/countryImages/Philippines.png" width="16" height="11"> 1 MYR = <font color="red">0.32 SGD</font>
<img src="images/countryImages/Singapore.png" width="16" height="11"> 1 MYR = <font color="red">33.40 LKR</font>
<img src="images/countryImages/SriLanka.png" width="16" height="11"> </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>
<img src="images/countryImages/Bangladesh.png" width="16" height="11"> 1 MYR = <font color="red">15.55 INR</font>
<img src="images/countryImages/India.png" width="16" height="11"> 1 MYR = <font color="red">3,185.11 IDR</font>
<img src="images/countryImages/Indonesia.png" width="16" height="11"> 1 MYR = <font color="red">304.00 MMK</font>
<img src="images/countryImages/myanmar.png" width="16" height="11"> 1 MYR = <font color="red">24.95 NPR</font>
<img src="images/countryImages/Nepal.png" width="16" height="11"> 1 MYR = <font color="red">24.65 PKR</font>
<img src="images/countryImages/PAKISTAN.png" width="16" height="11"> 1 MYR = <font color="red">11.10 PHP</font>
<img src="images/countryImages/Philippines.png" width="16" height="11"> 1 MYR = <font color="red">0.32 SGD</font>
<img src="images/countryImages/Singapore.png" width="16" height="11"> 1 MYR = <font color="red">33.40 LKR</font>
<img src="images/countryImages/SriLanka.png" width="16" height="11"> </font>
</b>
</div>
</div>
</div>
</div>
答案 0 :(得分: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的空格。