I want to parse html content titletag and this titletag's content number after get content number data.
<a title="%this%Content 3 - Java Programming" href="javascript:;" onclick="data('content_3');">
Java Programming<span style="font-size:10px;color:#D39D96"></span>
</a></div>
<div class="clear"></div>
<div style="display: none;font-size:14px;font-weight:bold;color:red;margin:10px;" id="content_3">%this%Content 3 Text</div>
I want to result is : %this%Content 3 - Java Programming and %this%Content 3 Text
But this html have more content in this manner. Maybe i was write in for loop.
答案 0 :(得分:0)
我试过这个为我工作:
public class Test {
public static void main(String[] args) {
String s = "<a title=\"%this%Content 3 - Java Programming\" href=\"javascript:;\" onclick=\"data('content_3');\">\n" +
"Java Programming<span style=\"font-size:10px;color:#D39D96\"></span>\n" +
"</a></div>\n" +
"<div class=\"clear\"></div>\n" +
"<div style=\"display: none;font-size:14px;font-weight:bold;color:red;margin:10px;\" id=\"content_3\">%this%Content 3 Text</div>";
Document document = Jsoup.parse(s);
Element element = document.select("a").first();
String linkHref = element.attr("title");
System.out.println(linkHref + document.select("div").last().text());
}
}