开发者

Reading HTML+JavaScript using Java

开发者 https://www.devze.com 2023-03-08 07:06 出处:网络
I can read the HTML contents via http (for example, http://www.foo.com) using Java (with URL and BufferedReader classes). However, a couple of them contain JavaScript. My current app cannot process Ja

I can read the HTML contents via http (for example, http://www.foo.com) using Java (with URL and BufferedReader classes). However, a couple of them contain JavaScript. My current app cannot process JavaScript.

What's the best way to read HTML content with JavaScript using Java?

I am open using o开发者_运维问答ther languages if it is easier.

Thanks in advance for your help.

UPDATE - Clarification:

A couple HTML contents are generated dynamically using JavaScript. I can see the result (in pure HTML after the JavaScript processing) when viewing them on a browser.

On the other hand, when my Java app retrieves the HTML contents, it says that there is no JavaScript on my app.

Ideally, I want to be able to get the same result as on the browser using my Java app.

Thanks for everyone's response.


HtmlUnit has good JavaScript support and it should (almost) parse the HTML as a web browser.

  • http://htmlunit.sourceforge.net/
  • http://htmlunit.sourceforge.net/javascript.html


Cobra (http://lobobrowser.org/cobra/getting-started.jsp) will fit your needs


For just HTML parsing you can use HTMLParser (org.htmlparser). However from the way you described your problem, it seems you need a browser, because executing is totally different than just parsing. Cheers.


With no doubt you need to use Java html parser:

  • Java Open Source HTML Parsers
  • Which Html Parser is best?
  • HTML/XML Parser for Java
  • HTML PARSER in java [closed]
0

精彩评论

暂无评论...
验证码 换一张
取 消