標籤:static ons status element 目標 enable page str timeout
public static String getHtml(String html){
// 類比一個瀏覽器
@SuppressWarnings("resource")
WebClient webClient = new WebClient();
//webclient參數載體
WebClientOptions clientOptions = webClient.getOptions();
// 設定webClient的相關參數
clientOptions.setJavaScriptEnabled(true);
clientOptions.setCssEnabled(false);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
clientOptions.setTimeout(35000);
clientOptions.setThrowExceptionOnScriptError(false);
// 類比瀏覽器開啟一個目標網址
HtmlPage rootPage = null;
try {
rootPage = webClient.getPage(html);
} catch (FailingHttpStatusCodeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//body html資訊
HtmlElement htmlElement = rootPage.getBody();
String xmlContent = htmlElement.asXml();
return xmlContent;
}
htmilunit-- 針對抓取js產生的資料