How to parse ul li Tags using jsoup in android

后端 未结 1 1521
既然无缘
既然无缘 2021-01-06 05:49

i m trying to develop a College Updates android app using JSOUP API and parsing content from college website . How can i parse ul, li tags and display them .

sample

相关标签:
1条回答
  • 2021-01-06 06:21

    First you need to close all spans.
    Here's a short example:

    String html;
    html = "<div class=\"moduletable_events\">";
    html += "<ul>";
    html += "<li class=\"_mce_tagged_br\"><span style=\"line-height: 1.4em;\"><span style=\"line-height: 1.4em;\">M.Tech Exam Ian-2014 TimeTable 1</span></span></li>";
    html += "<li class=\"_mce_tagged_br\"><span style=\"line-height: 1.4em;\"><span style=\"line-height: 1.4em;\">M.Tech Exam Feb-2014 TimeTable 2</span></span></li>";
    html += "</ul>";
    html += "</div>";
    
    //Document doc = Jsoup.connect("http://example.com/").get(); to load from url
    Document doc = Jsoup.parse(html);
    Elements div = doc.select("div.moduletable_events");  // select your div with yor class
    Elements ul = doc.select("div.moduletable_events > ul"); 
    Elements li = ul.select("li"); // select all li from ul
    
    for (int i = 0; i < li.size(); i++) {
        Log.d("jsoup", " " + li.get(i).select("span > span").text());     
    }
    Log.d("jsoup", "size: " + li.size());
    
    0 讨论(0)
提交回复
热议问题