Page MenuHomePhabricator
Paste P4559

phantomjs
ActivePublic

Authored by Ejegg on Dec 2 2016, 7:57 PM.
Referenced Files
F4950427: phantomjs
Dec 3 2016, 3:45 AM
F4947602: phantomjs
Dec 3 2016, 12:23 AM
F4946522: phantomjs
Dec 2 2016, 11:08 PM
F4943164: phantomjs
Dec 2 2016, 7:57 PM
Subscribers
None
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');