From: Ahmed A. <asa...@ya...> - 2014-02-26 14:52:01
|
Hi Jack, String html = "hello"; URL url = new URL("http://localhost"); StringWebResponse stringWebResponse = new StringWebResponse(html, url); WebClient webClient = new WebClient(); webClient.getOptions().setJavaScriptEnabled(false); HtmlPage page = HTMLParser.parseHtml(stringWebResponse, webClient.getTopLevelWindows().get(0)); Ahmed ________________________________ From: Jack Bi <814...@qq...> To: htm...@li... Sent: Wednesday, February 26, 2014 5:38 PM Subject: [Htmlunit-user] How to use htmlUnit execution of type String HTML page Hi all: Because of htmlUnit is very slow, so I thought of using httpclient to obtain page code. But the HTML code that I got is not I wanted, page with JS code need to be executed. I would like to know how to use htmlUnit execute the code. This is my code: HttpPost httpPost = new HttpPost(urlString); List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair(inputName, "https://twitter.com")); formparams.add(new BasicNameValuePair(selectName,optionValue)); httpPost.setEntity(new UrlEncodedFormEntity(formparams,HTTP.UTF_8)); HttpResponse response = httpClient.execute(httpPost); entity = response.getEntity(); htmlString = EntityUtils.toString(entity,HTTP.UTF_8); URL url = new URL(urlString); StringWebResponse webResponse = new StringWebResponse(htmlString, url); HtmlPage page = HTMLParser.parseHtml(webResponse, webClient.getCurrentWindow()); Thread.sleep(20*1000); But it cannot work.How can I do? Thank you very much! Jack -- View this message in context: http://htmlunit.10904.n7.nabble.com/How-to-use-htmlUnit-execution-of-type-String-HTML-page-tp33241.html Sent from the HtmlUnit - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Flow-based real-time traffic analytics software. Cisco certified tool. Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer Customize your own dashboards, set traffic alerts and generate reports. Network behavioral analysis & security monitoring. All-in-one tool. http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk _______________________________________________ Htmlunit-user mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/htmlunit-user |