Jsoup使用


     org.jsoup
     jsoup
     1.13.1
public class JsoupTest {

    public static void main(String[] args) throws Exception{
        String html = "First parse"
                + "

Parsed HTML into a doc.

gewgewg

"; Document doc1 = Jsoup.parse(html); doc1.getElementsByTag("p").forEach(e->System.out.println(e.text())); Document doc2 = Jsoup.connect("https://www.oschina.net/search?scope=project&q=%E7%88%AC%E8%99%AB") .data("query", "Java") .userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36") .cookie("auth", "token") .timeout(3000) .get(); doc2.getElementsByClass("project-item").forEach(e->System.out.println(e.outerHtml())); File input = new File("F:\\bak\\v2/websocket.html"); Document doc3 = Jsoup.parse(input, "UTF-8"); doc3.getElementsByTag("h1").forEach(e->System.out.println(e.outerHtml())); } }

 

你可能感兴趣的:(Jsoup使用)