7

Get a final HTML with Javascript rendered Java as String - codesd.com

 2 years ago
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

advertisements

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

I have a Java applet on a webp age which I am trying to code against with Javascript. public class WebCapture extends Applet { public String[] getSourceDeviceNames() { return new String[] {'Device 1', 'Device 2'}; } public void acquireImage() { //...

Adding images to html with javascript

I've tried some HTML DOM code from several sites, but it isn't working. It isn't adding anything. Does anyone have a working example on this? this.img = document.createElement("img"); this.img.src = "img/eqp/"+this.apparel+"/"

Strategies to render HTML with Javascript

I take a fat JSON array from the server via an AJAX call, then process it and render HTML with Javascript. What I want is to make it as fast as humanly possible. Chrome leads over FF in my tests but it can still take 5-8 seconds for the browser to re

get the relative URL with javascript

Is there an easy way to get the relative url with javascript? Im trying to use window.location.href but it returns the absolute path. What im trying to do is this: I have two pages; mobile.html and desktop.html. I want to use ONE javascript-file to d

Get a Boolean value with javascript

I want to get php booelan value with javascript. That is my code. <script type="text/javascript"> var $j = jQuery.noConflict(); var isValue = $j(<?php isset($getResult[]); ?>); alert(isValue); </script> It should be like this &

What is a clean and effective way to generate and add HTML with JavaScript or JQuery?

I was going to ask this question (until I found it was already asked) and now have the answer to that question: It's better to request JSON from a PHP script and then wrap the results in HTML with JavaScript. Now I have the unfortunate task of genera

Get the last line of HTML with Javascript

How can I get the last line of HTML text with Javascript? For example, a HTML request returns this response: <span>blah blah blah ha ha ha ha tatatatata How would I get the last line "tatatatata"? var html = document.getElementById('some_e

Get Element in div with Javascript

I want to disable/enable a button with Javascript. Because the Javascript is called, after a Flash animation is rendered, the button exists at the time of the execution. The button is in a hierarchy: <html><body><form#form1><div#contr

Deal with NL2BR from database to HTML with Javascript

I am having difficulty with displaying HTML it seems. haha, let me explain. I have 1 template file for "comments"... and it tells things where to go and such in the html. When Adding, Updating and Selecting any of the "comments" IE: &l

Add html with javascript string

Im trying to append html with a javascript string, but having some troubles with the single quotes. Appending the element works this far: $("<a class='action-button' id='pl65197buy' value='buy now'>Bekijk aanbieding</a>").prependTo(&

Get a file entry with javascript?

I have this line in HTML: <input class="input-file" type="file" id="input-recipe-pic"> After a user selects a file to upload, and presses the submit button, I am trying to get the file they selected from the file input

Import XML into HTML with javascript

I am trying to import a XML-file into a HTML document with Javascript. It works fine for Firefox, but it doesn't work for IE-10 and Chrome. My script: if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpReq

How to get an Ajax variable with Javascript

Underneath i have added my ajax script named checkMessages.php: $user = $system->getUserInfo($_SESSION['user_id']); $checkmes = $db->query("SELECT * FROM notifications WHERE receiver_id='".$user."' AND sent='0'"); $checkmes = $ch

Game frame: why do we transmit data as JSON and inject it in HTML with JavaScript on the client side?

I'm a bit new to web-development and the Play framework in particular, I just have seen several Play tutorials, and every single tutorial I have seen so far returns a list of models as JSON to the client and then constructs the HTML list out of JSON

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK