![](/style/images/good.png)
![](/style/images/bad.png)
Get a final HTML with Javascript rendered Java as String - codesd.com
source link: https://www.codesd.com/item/get-a-final-html-with-javascript-rendered-java-as-string.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Get a final HTML with Javascript rendered Java as String
I want to fetch data from an HTML page(scrape it). But it contains reviews in javascript. In normal java url fetch I am only getting the HTML(actual one) without Javascript executed. I want the final page with Javascript executed.
Example :- http://www.glamsham.com/movies/reviews/rowdy-rathore-movie-review-cheers-for-rowdy-akki-051207.asp
This page has comments as a facebook plugin which are fetched as Javascript.
Also similar to this even on this. http://www.imdb.com/title/tt0848228/reviews
What should I do?
Use phantomjs: http://phantomjs.org
var page = require('webpage').create();
page.open("http://www.glamsham.com/movies/reviews/rowdy-rathore-movie-review-cheers-for-rowdy-akki-051207.asp")
setTimeout(function(){
// Where you want to save it
page.render("screenshoot.png")
// You can access its content using jQuery
var fbcomments = page.evaluate(function(){
return $(".fb-comments iframe").contents().find(".postContainer")
})
},10000)
You have to use the option in phantom --web-security=no
to allow cross-domain interaction (ie for facebook iframe)
To communicate with other applications from phantomjs you can use a web server or make a POST request: https://github.com/ariya/phantomjs/blob/master/examples/post.js
Related Articles
Java Applet calling method with Javascript returning [Ljava.lang.String; @ 7ac79dfa
Adding images to html with javascript
Strategies to render HTML with Javascript
get the relative URL with javascript
Get a Boolean value with javascript
What is a clean and effective way to generate and add HTML with JavaScript or JQuery?
Get the last line of HTML with Javascript
Get Element in div with Javascript
Deal with NL2BR from database to HTML with Javascript
Add html with javascript string
Get a file entry with javascript?
Import XML into HTML with javascript
How to get an Ajax variable with Javascript
Game frame: why do we transmit data as JSON and inject it in HTML with JavaScript on the client side?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK