java爬蟲工具htmlunit hello word示例(附帶親測可用所有jar包)
阿新 • • 發佈:2019-01-09
htmlunit這裡就不介紹了。筆者剛接觸這個時候給這個jar包問題折磨了一會。
現把jar包都歸納起來。附帶下載連結:htmlunit基本jar包
可能有的還需要這兩個包:
匯入以上所有jar包之後來hello word一下。
public static void main(String[] args) throws IOException { // 例項化Web客戶端 WebClient webClient = new WebClient(); // 爬取https網站需要設定為true webClient.getOptions().setUseInsecureSSL(true); // 解析獲取頁面 HtmlPage page = webClient.getPage("https://www.baidu.com"); // 獲取Html System.out.println("網頁html:" + page.asXml()); System.out.println("===================="); // 獲取文字 System.out.println("網頁文字:" + page.asText()); }
這裡就可以正常爬取咯。剩下的邏輯就看你自己咯。