[HtmlUnit]Fetch Dynamic Html/Content Created By Javascript/Ajax
import com.gargoylesoftware.htmlunit.*; import com.gargoylesoftware.htmlunit.html.HtmlPage; import java.net.*; public class helloworld { public static void main(String[] args) throws Exception { final WebClient webclient=new WebClient(BrowserVersion.FIREFOX_3_6); /* * htmluni 2.11 version * webclient.setJavaScriptEnabled(true); webclient.setCssEnabled(false); webclient.setAjaxController(new NicelyResynchronizingAjaxController()); webclient.setTimeout(5000); webclient.setThrowExceptionOnScriptError(false); */ webclient.getOptions().setJavaScriptEnabled(true); webclient.getOptions().setCssEnabled(false); webclient.getOptions().setThrowExceptionOnScriptError(false); URL url=new URL("https://www.coursera.org/course/gametheory"); HtmlPage page=webclient.getPage(url); Thread.sleep(1000*30); String ori = page.asXml(); System.out.print(ori); //System.out.println(page.getHtmlElementById("cart-empty").asXml()); } }
------------------------------------------
除非特别声明,文章均为原创,版权与博客园共有,转载请保留出处
BUY ME COFFEE