segment-boneyard / nightmare

A high-level browser automation library.
https://open.segment.com
19.55k stars 1.08k forks source link

Get the page content #196

Closed aliminnet closed 9 years ago

aliminnet commented 9 years ago

In PhantomJs we can get the content of page like this:

var page = require('webpage').create();
....
var content = page.content;

What is the best way to get the content is nightmarejs?(I can see evaluate can help but I think it is not very good solution)

hugoeanogueira commented 9 years ago

x2

rclai commented 9 years ago

Can't you just evaluate and return the HTML from it?

aliminnet commented 9 years ago

I figured out like this:

new Nightmare(options)
  .goto('http://www.blablabla.com/')
  .wait()
  .evaluate(function () {
        return document.documentElement.outerHTML;
     }, function (result) {
        console.log( result);
     }
  ).run(function( err, nightmare){
    console.log("done");
  });