2

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 other 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.

5
  • 2
    What are you doing with the contents returned by a URL after reading from it? Are you evaluating the JavaScript? Commented May 23, 2011 at 19:51
  • Not sure that I correctly understand your question. You can use SWT Browser widget. It can render HTML and supports JavaScript. Commented May 23, 2011 at 19:53
  • @pion What do you mean by "it says that there is no JavaScript on my app". Who says that ? Is it the HTML you got which contains this exact text ? Then you should consider modifying your User Agent String to get the correct content first. HTMLUnit can help you for that and is definitely the best way to go. Commented Jan 4, 2012 at 9:42
  • I have same proplem , can u help me ? stackoverflow.com/questions/20781322/… Commented Dec 26, 2013 at 14:25
  • @pion did my answer helped? Commented Feb 13, 2016 at 14:36

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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.

Comments

-3

With no doubt you need to use Java html parser:

1 Comment

99 of 100 HTML parsers in Java don't understand/execute JavaScript. Please be more specific.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.