1. Want to use node and cheerio to grab data in the network, and then use it in another module, but because it is asynchronous to obtain data, the current Synchronize code has been executed, the obtained variables or return are empty, exports can not be exported, in addition to temporary use or storage in the processing function, is there any way to continue to use, or export to another module, return.
2.`function getTitle (url,i) {
console.log ("getting contents of page" + iTunes");
http.get(url+i+".html",res=>{
var chunks = [];
res.on("data",function(chunk){
chunks.push(chunk);
});
res.on("end",function(){
var html = iconv.decode(Buffer.concat(chunks),"gb2312");
var $ = cheerio.load(html,{decodeEntities:false});
var asyRes = $(".co_content8 .ulink");
$(".co_content8 .ulink").each(function(index,ele){
var dom = $(ele);
titles.push({
title:dom.text()
})
});
if (i<2) {
getTitle(url,PPindex);
//
}else {
// if (titles) {
// save(titles);
// }
//,..titles
}
})
});
} `