jsoup的使用方法可以在他的官网上找到
使用比较简单,像是jquery的操作
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
public class MyJsoup {
private static String URL_Path = "http://sauzny.iteye.com/";
public static void main(String[] args) throws IOException {
Document doc = Jsoup.connect(URL_Path)
.data("query", "Java") // 请求参数
.userAgent("I ’ m jsoup") // 设置 User-Agent
.cookie("auth", "token") // 设置 cookie
.timeout(3000) // 设置连接超时时间
.get(); // 使用 GET 方法访问 URL ;
Element div = doc.getElementById("blog_actions");
System.out.println(div.getElementsByTag("ul").get(0).getElementsByTag("li").get(0).text());
}
}