0

I want to print complete rendered HTML using Java.For this I searched a lot on Google and also found some questions on SO Like

1: How do you render HTML using Java?
2: HTML parsing using java
3: Rendering (streaming) HTML into Pane

But unfortunately they were not helpful for me.
So the thing which I want to print is a rendered HTML. When I try do it with using simple java , Then it didn't print the executed JavaScript (instead it prints the JavaScript which is written in the HTML page).
Please Guide me about this
SO SIMPLY I AM TRYING TO PRINT THE RENDERED HTML BY BROWSER (not the html file present at web server) INCLUDING EXECUTED JAVASCRIPT.
Thanks

1
  • JSoup? It's what I use to parse HTML. Not sure if it renders but it might be worth a look. Commented Nov 26, 2013 at 16:03

2 Answers 2

0

There are a bunch of packages that you can find that are similar to Hypirinha on the net , if you look for them.

There is probably a better answer than mine, but I thought this would be an idea that might work for you.

Also, here is a JavaFX example, but I am not sure if it suits your purpose.

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

8 Comments

Let me ask simply: Does this API have methods who print ALL RENDERED html on console as a String?
Yes, there is an example on that page, but of course, you need to create the JavaFX (or Swing) console yourself, which is a pretty simple thing to find on the net.
I dont want to capture all elements one by one becuase I dont know what is in HTML which I am trying to parse.So will this API works for this? because I seen that It have methods which capture them through body , head etc
Sorry, I am not completely understanding what you are trying to do.
I AM TRYING TO PRINT THE RENDERED HTML BY BROWSER (not the html file present at web server) INCLUDING EXECUTED JAVASCRIPT.The code return the html written in file NOT THE HTML RENDERED IN BROWSER.Simply I wan to get that HTML which we can see using firebug
|
0

I've made a SimpleBrowser component to get html from a WebView. Usage:

SimpleBrowser browser = new SimpleBrowser();

Scene scene = new Scene(browser);

browser.load("http://stackoverflow.com", new Runnable() {
    @Override
    public void run() {
        System.out.println(browser.getHTML());
    }
});

Code is available in this answer or in this gist.

6 Comments

Seems good :) I have no knowledge about javafx.Does this code works in simple java project?
Yes, this requires JDK 7. It also runs in JDK 8 early access.
Actually I want to do it in Java not in JavaFX
JavaFX is a part of JDK since early versions of JDK7, it's just the same good old Java which adopted the WebKit engine. :-)
I have tried your solution But I didn't work.I guess you are not getting my point.I AM TRYING TO PRINT THE RENDERED HTML BY BROWSER (not the html file present at web server) INCLUDING EXECUTED JAVASCRIPT.
|

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.