PhantomJS and Twitter

34 views
Skip to first unread message

Andrew Goh

unread,
May 10, 2022, 12:35:00 PM5/10/22
to phantomjs
This code works differently depending on the timeout:

var page = require('webpage').create();
page.open('https://twitter.com/phantomjs', function (status) {
  if (status !== 'success') {
    console.log('Unable to access network');
  } else {
    setTimeout(function () {
      var title = page.evaluate(function () {
      return document.title;
      });
      console.log(title);
      phantom.exit();
    }, 5000);
  }
});

with a timeout of 5000ms, the title is
"PhantomJS (@PhantomJS) / Twitter"
and it is the PhantomJS profile

change the timeout to 0, the title is
"Profile / Twitter"
and you get the login page.

I fumbled all over this initially with different codes, placing the phantom.exit() outside the timeout and there is no response for the 5 seconds timeout. I thought initially that it relates to the viewport size, it isn't.

lots of such pit falls all over the web with dynamic javascripts.
Reply all
Reply to author
Forward
0 new messages