-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredirect.js
41 lines (38 loc) · 1.02 KB
/
redirect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var page = require('webpage').create();
var system = require('system');
var args = system.args;
var DEBUG = false;
var fs = require('fs');
function ValidUrl(str) {
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
if(!pattern.test(str)) {
return false;
} else {
return true;
}
}
if(args.length != (1+1) ){
console.log('error: lack of parameters');
phantom.exit();
}
else{
var temp_url = args[1];
if(ValidUrl(temp_url)){
page.open(temp_url, function () {
var url = page.evaluate(function() {
return url;
});
url = url.substring(url.indexOf('www.'));
url = decodeURIComponent(url).replace('hotelscombined','');
console.log(url);
phantom.exit();
});
}else{
phantom.exit();
}
}