Timer on JS

54 views
Skip to first unread message

Tom Dalton

unread,
Aug 3, 2016, 12:52:20 PM8/3/16
to phantomjs

Hey everyone,

I've a problem with phantom js.
First, i wanted to capture any website using php or js, so i choosed phantomjs.
This is my script :

var page = require('webpage').create();
page.viewportSize = { width: 1920, height: 1080 };
page.open('http://example.com/', function() {
  page.render('example.png');
  phantom.exit();
});

It work well but there is some websites which use ads or component which take time to show.
I'd like to add a timer like that :
wait 5 seconds for showing all website component
capture the website with all component loaded

instead of :
capture the website without component loaded.

It's really anonnoying,
so i would be really grateful for the one who can make a script with a timer.

Thanks everyone
Tom (Sorry for my bad english)

Bo Zou

unread,
Aug 3, 2016, 2:06:58 PM8/3/16
to phantomjs
you have several options:

1. knysa: https://github.com/pahakia/knysa
    kflow.sleep(5000);
2. use casper.waitFor(): http://docs.casperjs.org/en/latest/modules/casper.html#waitfor

Tom Dalton

unread,
Aug 4, 2016, 8:16:58 AM8/4/16
to phantomjs
Hey Bo Zou,



Really thank for those links, i'm really grateful to you.
I've another question.
I'd like to know if there's a phantomjs function for clearing cache, cookies and other website thing, or it's automaticaly did before screen capture.


Thanks mate,
Good Afternoon

Tom Dalton

unread,
Aug 4, 2016, 9:16:43 AM8/4/16
to phantomjs
Hey,

I have just tested knysa and i've found some problem.
First,
I downloaded the knysa folder from github to my home folder.
I've make this alias:
alias knysa="sh /home/knysa-master/knysa.sh" in ubuntu.
I went to the folder which contains the script to run and added this line :

var page = require('webpage').create();
page.viewportSize = { width: 1920, height: 1080 };
page.open('http://test.com/', function() {
  kflow.sleep(5000);
  page.render('test.png');
  phantom.exit();
});

after i ran this command :
knysa test.js

It didn't show error and made file called test.js.js.
It also didn't solve my problem because it took a screen capture directly without wait 5 seconds.

So if you can help me, i'm new from coding.

Thanks really
Tom

Bo Zou

unread,
Aug 8, 2016, 11:33:50 AM8/8/16
to phantomjs
try this:

kflow.open('http://test.com/');

kflow.sleep(5000);
kflow.render("test.png");

Bo Zou

unread,
Aug 8, 2016, 11:34:19 AM8/8/16
to phantomjs
sorry, I don't know, you'll need to check phantomjs doc.
Reply all
Reply to author
Forward
0 new messages