I am making a chat bot using Node.js. I use cheerio to scrape information from html and send it to users. I can scrape data and print it threw console but cannot return that information to a variable. Please help.
--Parsing part--
const cheerio = require("cheerio"),
request = require("request");
const init_url = "https://stu.dje.go.kr/sts_sci_md01_001.do?schulCode=G100000208&schulCrseScCode=4&schulKndScCode=04&schMmealScCode=2";
const MealParser = {};
MealParser.parse = () => {
console.log(''+init_url);
return doRequest(makeURL(),function(err,data){
console.log(data);
return data;
});
}
function doRequest(url,callback){
request(url, function(err, resp, html) {
var list = ["initial array"];
if (!err){
const $ = cheerio.load(html);
$('.tbl_type3 th:contains("중식")').parent().children().each(function () {
list.push($(this).text());
});
return callback(null,list);
}
});
}
function makeURL(){
var result_url = init_url;
return result_url;
}
module.exports = MealParser;
I use function "parse" to return the scrapped information to the main bot which looks like the code down below.
--using the parsed information--
var result = MealParser.parse();