Coder Social home page Coder Social logo

Comments (7)

ehartford avatar ehartford commented on August 17, 2024

What other methods? I would like to know please.

from node-phantom.

ehartford avatar ehartford commented on August 17, 2024

+1 by the way.

from node-phantom.

DavidLeoni avatar DavidLeoni commented on August 17, 2024

You just need to evaluate document.documentElement.innerHTML inside the opened page, like I do here after a timeout, to take into account presence of Javascript inside the page that could modified it on load:

var phantom=require('node-phantom');    
var waitTime = 5000;

phantom.create(function(err,ph) {    
    return ph.createPage(function(err,page) {
    /* to show browser console.log

        page.onConsoleMessage = function(msg) {
        console.log(msg);
    }; */
        var pstr = "http://www.google.com";
        console.log("browsing to ", pstr);
        return page.open(pstr, function(err,status) {
            console.log("opened site? ", status);
            if ( status === "success" ) {
                setTimeout(function(){                   
                    var p = page.evaluate(function () {
                        return document.documentElement.innerHTML;                    
                    }, function(err,result){
                        if (err) {
                            console.log("Error!");
                        } else {
                                console.log("*****   The html is:   *****");                                
                                console.log(result);                              
                        }                        
                        ph.exit();
                    });                                               

                }, waitTime)                   
            };
        });
    });                        
});

from node-phantom.

alexscheelmeyer avatar alexscheelmeyer commented on August 17, 2024

You can get to page.content through the page.get function

page.get('content',function(err,content){
  //content will now be 'page.content'
});

from node-phantom.

JeStasG avatar JeStasG commented on August 17, 2024

in code:

page.get('content',function(err,content){
  //content will now be 'page.content'
});

page content consist in variable err

PS: Sorry fo my english:(

from node-phantom.

raeesaa avatar raeesaa commented on August 17, 2024

@alexscheelmeyer We are getting content in err object of page.get('content', function(err, content){}) function and content object is undefined. Has the callback method signature changed since this answer was posted?

Thanks,
Raeesaa

from node-phantom.

tholu avatar tholu commented on August 17, 2024

@raeesaa
This should work:

page.get('content',function(content){
  //content will now be in var 'content'
});

from node-phantom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.