java解析html的table

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class test11 {

    public static void main(String[] args) {// TODO Auto-generated method stub
        String html = "html内容";
        Document doc = Jsoup.parse(html);
        Elements rows = doc.select("table[class=h_list-table]").get(0).select("tr");
        
        if (rows.size() == 1) {
                System.out.println("没有结果");
        }else {
            for(int i=1;i)
            {
                System.out.println("-----------------------------------------------------------------");
                Element row = rows.get(i);
                    System.out.println("学校名称:" + row.select("td").get(0).text());
                System.out.println("学校代码:" + row.select("td").get(1).text());   
                System.out.println("-----------------------------------------------------------------");
            }
        }
    }
}

 

你可能感兴趣的:(java解析html的table)