简体   繁体   中英

Java jsoup parsing specific tag

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.

I have Tried this working for me:

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());


    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM