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());
}
}
}请各位前辈帮忙分析一下这个程序,这到底是什么意思???
很显然,完全没有用到Elements doc = document.select("a");这行代码,亲.
<div id="div1">
<a>1</a>
<a>2</a>
</div>
<div id="div2">
<a>3</a>
<a>4</a>
</div>
有1、2、3、4的,没有div1和div2的