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")); } } }
执行结果如下: