const HTMLParser = require('node-html-parser');
const normalizeWhitespace = require('normalize-html-whitespace');
const axios = require('axios').default;
const pages = {
'fauchon': 'https://www.hotenavi.com/jht01/empty/?account_id=11',
'dwave': 'https://www.hotenavi.com/jht02/empty/?account_id=11',
'perrier': 'https://www.hotenavi.com/jht03/empty/?account_id=11',
'jmex': 'https://www.hotenavi.com/jht04/empty/?account_id=11',
'han-an': 'https://www.hotenavi.com/jht05/empty/?account_id=11',
'pasha': 'https://www.hotenavi.com/jht06/empty/?account_id=11',
'pasha-resort': 'https://www.hotenavi.com/jht07/empty/?account_id=11'
}
getPage = async (pageUrl) => {
const response = await axios.get(pageUrl);
const root = HTMLParser.parse(response.data);
const value = root.querySelector('.epEmptyRoomTxt').firstChild._rawText;
const normalized = normalizeWhitespace(value);
return normalized.replace(' ','').replace('室','');
}
main = async () => {
try {
const pageKeys = Object.keys(pages);
for(const pageKey of pageKeys) {
const response = await getPage(pages[pageKey]);
console.log(pageKey,':' , response);
await sleep(10000);
}
}
catch(error) {
console.error(error);
}
}
sleep = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms));
}
main();