forked from ariya/phantomjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Page Automation
ariya edited this page Sep 23, 2012
·
2 revisions
Because PhantomJS can load and manipulate a web page, it is perfect to carry out various page automations.
Since the script is executed as if it is running on a web browser, standard DOM scripting and CSS selectors work just fine.
The following useragent.js example demonstrates reading the innerText property of the element whose id is myagent:
var page = require('webpage').create();
console.log('The default user agent is ' + page.settings.userAgent);
page.settings.userAgent = 'SpecialAgent';
page.open('http://www.httpuseragent.org', function (status) {
if (status !== 'success') {
console.log('Unable to access network');
} else {
var ua = page.evaluate(function () {
return document.getElementById('myagent').innerText;
});
console.log(ua);
}
phantom.exit();
});The above example also demonstrates a way to customize the user agent seen by the remote web server.
(To be written)