public class ExampleJsoup {
public static void main(String args[]) {
try {
ExampleJsoup exampleJsoup = new ExampleJsoup();
exampleJsoup.Example1();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void Example1() throws IOException {
Document doc = Jsoup.connect("https://blog.csdn.net/final0402").get();
//获得网页title
String title = doc.title();
System.out.println( title );
//获得url中的scirpt
String data = doc.data();
System.out.println( data );
String val = doc.val();
System.out.println( "val = \n" + val );
//获得url中的请求的地址
String uri = doc.baseUri();
System.out.println( "uri = \n" + uri );
//获得url中的css
String cssSelector = doc.cssSelector();
System.out.println( "cssSelector = \n" + cssSelector );
//获得url中的网页脚本
String html = doc.html();
System.out.println( "html = \n"+ html );
//获得body中内容
String body = doc.body().text();
System.out.println( "body = \n"+ body );
//获得id=asideArchive,dom
Element content = doc.getElementById("asideArchive");
System.out.println( "content = \n"+ content );
//获得a href集合
Elements links = doc.select("a[href]");
System.out.println( "links = \n"+ content );
//获得所有src集合
Elements srcs = doc.select("[src]");
System.out.println( "srcs = \n"+ srcs );
//获得link href集合
Elements linkHrefs = doc.select("link[href]");
System.out.println( "linkhref = \n"+ linkHrefs );
//:lt(n) :gt(n)
//eq(1)
}
}