-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddr_img.js
31 lines (30 loc) · 981 Bytes
/
addr_img.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
var page = require('webpage').create(),
url = "http://www.starwoodhotels.com/preferredguest/directory/hotels/all/list.html?language=en_US"
page.open(url, function (status) {
if (status !== 'success') {
console.log('error: Unable to access network '+ status);
phantom.exit();
} else {
var results = page.evaluate( function() {
var list = document.querySelectorAll('.propertyName');
var result = {};
for (i = 0; i < list.length; i++) {
lines = list[i].innerText;
id = list[i].getAttribute('href');
if(id == null){
continue;
}
// console.log("HTML: "+list[i].getAttribute('href'));
id = Number(id.substring(id.indexOf('ID=')).substring(3));
// console.log(lines+" : " + id);
result[lines] = {id: id};
}
return result;
});
console.log(JSON.stringify(results));
phantom.exit();
}
});
page.onConsoleMessage = function (msg) {
console.log(msg);
};