Skip to content

Instantly share code, notes, and snippets.

@anaynayak
Created October 9, 2013 13:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anaynayak/6901447 to your computer and use it in GitHub Desktop.
Save anaynayak/6901447 to your computer and use it in GitHub Desktop.
phantom.js script to log all http requests from a page
var page = require('webpage').create(),
system = require('system'),
address;
if (system.args.length === 1) {
console.log('Usage: phantomjs url_requests.js http://some.url.com');
phantom.exit(1);
} else {
address = system.args[1];
var logUrl = function (req) {
console.log(req.url);
};
page.onResourceRequested = logUrl;
page.onResourceReceived = logUrl;
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
}
phantom.exit();
});
}
@anaynayak
Copy link
Author

Use the following to generate unique list of urls accessed from the page:

phantomjs url_requests.js http://some.url.com | sort | uniq 

and

phantomjs url_requests.js http://gmail.com | cut -d'/' -f3 | sort | uniq

to get a list of unique domains

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment