I'm using cURL to access a number of different pages. I want an elegant way of checking if the page has a javascript redirect. I could check for presence of a window.location
in the body, but because it may be inside a .js file or using a library like jQuery, it seems like any solution wouldn't be perfect. Anyone have any ideas?
Thanks to Ikstar for pointing out phantomjs I worked out the following example:
test.js
var page = require('webpage').create();
var testUrls = [
"http://www.google.nl",
"http://www.example.com"
];
function testNextUrl()
{
var testUrl = testUrls.shift();
page.open(testUrl, function() {
var hasRedirect = page.url.indexOf(testUrl) !== 0;
console.log(testUrl + ": " + hasRedirect.toString());
if (testUrls.length) {
testNextUrl();
} else {
phantom.exit();
}
});
}
testNextUrl();
Result:
D:\Tools\phantomjs-1.7.0-windows>phantomjs test.js
http://www.google.nl: false
http://www.example.com: true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With