getcvs
Version:
getcvs @manager-center
46 lines (37 loc) • 1.25 kB
JavaScript
const cheerio = require('cheerio');
const FormData = require('form-data');
const axios = require('axios').create({
withCredentials: true
})
const url = 'https://www.ibon.com.tw/retail_inquiry_ajax.aspx';
let getStrores = async (keywords) => {
const formData = new FormData();
formData.append("strTargetField", "COUNTY");
formData.append("strKeyWords", keywords);
return await axios.post(
url,
formData,
{
// You need to use `getHeaders()` in Node.js because Axios doesn't
// automatically set the multipart form boundary in Node.
headers: formData.getHeaders()
}
).then(res => {
const $ = cheerio.load(res.data);
var stores = $('tr').map((index, obj) => {
let id = $(obj).find('td').eq(0).text().trim();
return {
id,
// city: city,
store: $(obj).find('td').eq(1).text().trim(),
address: $(obj).find('td').eq(2).text().trim(),
url: `https://www.ibon.com.tw/retail_inquiry_showinfo.aspx?store_ID=${id}`
}
}).get();
stores.splice(0, 1);
return stores;
})
}
module.exports = {
getStrores
}