I tried to make crawling module but I can't get return value.
.then() is no use because it works in then itself. I have to get result out of .then().
I tried to use await but it is no use.
const request = require("request");
const cheerio = require("cheerio");
let data = new Array();
const getHTML = async(url) => {
request(url, (error, response, body) => {
if (error) throw error;
let $ = cheerio.load(body);
$('body .web-results-list .web-result').each(function (index, elem){
let title = $(elem).find('.web-result-title').text();
let linkadd = $(elem).find('.web-result-url').text();
let content = $(elem).find('.web-result-description').text();
data.push([title, linkadd, content]);
//console.log(title);
//console.log(linkadd);
//console.log(content);
})
}
);
return data
}
const func = async() => {
data = await getHTML("https://www.search.com/web?q=apple");
}
func();
console.log(data);
console result = []
How can I fix it?