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

Community
  • 1
  • 1
Despicable
  • 3,797
  • 3
  • 24
  • 42

2 Answers2

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.

djangofan
  • 28,471
  • 61
  • 196
  • 289
  • 1
    Let me ask simply: Does this API have methods who print ALL RENDERED html on console as a String? – Despicable Nov 26 '13 at 15:47
  • 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. – djangofan Nov 26 '13 at 15:50
  • 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 – Despicable Nov 26 '13 at 16:00
  • Sorry, I am not completely understanding what you are trying to do. – djangofan Nov 26 '13 at 17:54
  • 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 – Despicable Nov 27 '13 at 11:51
  • That's easy. You can use PhantomJS or Selenium and just call the getSource() method. As the dom changes, with user interaction, the getSource() method will get the latest version of the DOM content. – djangofan Nov 27 '13 at 15:40
  • I really appreciate your help .Selenium webDriver/firefoxDriver's getSource() returns the page source without executed javascript.I have tried it and didn't get the portion of javascript as executed :( .. May be I need a thing work like Web Server :( Please Guide me more about this if you can – Despicable Nov 28 '13 at 16:08
  • You might be able to use the Selenium JavascriptExecutore class to get it. Basically, you can use JavaScript to get the JavaScript headers. You can test your ideas using the Firebug Javascript console. Just a thought. I am running out of ideas for you. – djangofan Nov 28 '13 at 17:45
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.

Community
  • 1
  • 1
Andrey Chaschev
  • 16,160
  • 5
  • 51
  • 68