jsoup 获取指定页面的所有链接(需后续完善)

java代码如下:

import java.io.IOException;

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

public class ListLinks {

	public static void main(String[] args) throws IOException {
		String url = "http://www.baidu.com/";

		Document doc = Jsoup.connect(url).get();
		Elements links = doc.select("a[href]");
		for (Element link : links) {
			System.out.println(link.attr("href"));
		}

	}

}

执行结果如下:

posted on 2015-11-19 19:50  奈何作贼  阅读(586)  评论(0编辑  收藏  举报

导航