日期:2014-05-20 浏览次数:21097 次
public static void main(String[] args) throws Exception, IOException { Document document = Jsoup.parse(new URL("http://www.lvping.com/hotels-d1-beijing.html"), 2000); Elements doc = document.select("a"); printElements(document.children(), 0); } public static void printElements(Elements elements, int i) { i++; for (Element element : elements) { if (element.children().size() > 0) { // System.out.println(i + "|" + Strings.repeat("-", // i));//可以注释掉这行看效果 printElements(element.children(), i); } else { if (!Strings.isNullOrEmpty(element.text().trim())) System.out.println(element.nodeName()); System.out.println(i + "|" + Strings.repeat("-", i) + "" + element.text()); } } }