filterはIE8だと利用できないです。
links.js
var page = require('webpage').create()
,system = require('system')
,ua, url;
if (system.args.length != 3) {
console.log('[Error] Invalid Argument...');
phantom.exit();
} else {
url = system.args[1];
ua = system.args[2];
page.settings.userAgent = ua;
page.open(url, function (status) {
if (status !== 'success') {
console.log('[Error] Unable to load the [' + url + '] ...');
} else {
var ret = page.evaluate(function () {
var aTag = document.links;
var aTagList = [];
var domain = location.href.match(/^[httpsfile]+:\/{2,3}([0-9a-z\.\-:]+?):?[0-9]*?\//i)[1];
for (var i = 0, len = aTag.length; i < len; i++) {
if (aTag[i].href.indexOf(domain) == -1) continue;
aTagList.push(aTag[i].href);
}
var aTagUniqueList = aTagList.filter(function (x, index, self) {
return self.indexOf(x) === index;
});
return aTagUniqueList.join("\n");
});
console.log(ret);
}
phantom.exit();
});
}