Page MenuHomePhabricator
Paste P4559

phantomjs
ActivePublic

Authored by Ejegg on Dec 2 2016, 7:57 PM.
phantom.clearCookies();
var page = require('webpage').create(),
system = require('system'),
gotCookie = false;
page.onResourceReceived = function(response) {
var headers = response.headers,
len = headers.length,
i = 0;
if ( !gotCookie ) {
for ( i=0; i< len; i++ ) {
if ( headers[i].name == "Set-Cookie" ) {
console.log( JSON.stringify({ cookie: headers[i].value} ));
gotCookie = true;
}
}
}
var data = page.evaluate( function() {
if ( !window.mediaWiki ) {
return false;
}
if ( !mediaWiki.centralNotice ) {
return false;
}
if ( mediaWiki.centralNotice.choiceData && mediaWiki.centralNotice.data ) {
return {
data: mediaWiki.centralNotice.data,
choiceData: mediaWiki.centralNotice.choiceData,
choiceVersion: mediaWiki.loader.getVersion('ext.centralNotice.choiceData')
};
} else {
return false;
}
} );
if ( data ) {
console.log( JSON.stringify( data ));
phantom.exit();
}
};
var lang = 'en';
if (system.args.length > 1) {
lang = system.args[1];
}
page.open('https://' + lang + '.wikipedia.org/wiki/Special:Random');