2

I try to capture some images from the new relic insights dashboard, but it won't work.

The script works a few weeks ago, but now, I just get some empty images with an orange border at the top (like if JavaScript was not enabled).

There's my script: http://pastebin.com/aiBiWXqK

It works for the login page, but for the 2 other captures, it show an empty page.

I run this script like this in an .sh file.

PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs /usr/local/bin/casperjs --cookie-file=$(pwd)/tv-cookies.txt $(pwd)/capture.js --ssl-protocol=any --ignore-ssl-errors=true

I tried to casper.wait(fun, 300000) to be sure it will completely load.

I tried to to casper.waitForSelector('.dashboard-widgets', fn) to check if the selector is created, but it won't work.

I know the dashboard is created with Angular, but I tried to capture other websites made with Angular and it's ok.

Does anyone know how to make it? Or any advice or other packages to use to do this?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Crak_mboutin
  • 1,046
  • 2
  • 12
  • 18

2 Answers2

1

I tried Nightmare.js! It works #1! Pretty easy to understand and to read!

var nightmare = Nightmare();
var NRdashboard = nightmare
  .viewport(1920, 1080)
  .useragent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36')
  .goto('https://login.newrelic.com/login')
  .wait()
  .screenshot(content_dir + '/others/nightmare/login.png')
  .type('#login_email', '***')
  .type('#login_password', '***')
  .screenshot(content_dir + '/others/nightmare/loginFilled.png')
  .click('#login_submit')
  .wait(2000)
  .screenshot(content_dir + '/others/nightmare/dashboard.png')
  .goto('https://insights.newrelic.com/accounts/123456')
  .wait(2000)
  .screenshot(content_dir + '/others/nightmare/dashboard2.png')
  .run(function (err, nightmare) {
      if (err) return console.log(err);
      console.log('Done!');
  });
Crak_mboutin
  • 1,046
  • 2
  • 12
  • 18
0

The CasperJS commandline usage is something like this:

casperjs [options] script [script_args]

The problem is that you're opening a https site in an older version of PhantomJS, so you need to the --ssl-protocol=any --ignore-ssl-errors=true commandline options (here's why). As you can see in the above "usage", the options that CasperJS needs to pass through to PhantomJS aren't actually given to CasperJS itself, but rather to the script.

Move the two necessary commandline options one argument to the front:

PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs /usr/local/bin/casperjs --cookie-file=$(pwd)/tv-cookies.txt --ssl-protocol=any --ignore-ssl-errors=true $(pwd)/capture.js
Community
  • 1
  • 1
Artjom B.
  • 61,146
  • 24
  • 125
  • 222