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;
}