测试代码:
import java.io.File;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class Test {
public static void main(String[] args) {
Test t = new Test();
t.parseUrl();
}
public void parseUrl() {
try {
Document doc = Jsoup.connect("
http://www.baidu.com/").get();
Elements hrefs = doc.select("a[href]");
System.out.println(hrefs);
System.out.println("------------------");
System.out.println(hrefs.select("[href^=http]"));
} catch (IOException e)
{
e.printStackTrace();
}
}
}
编译执行:
javac -cp jsoup-1.7.1.jar:. Test.java
java -cp jsoup-1.7.1.jar:. Test
测试结果【截图】: