By default methodB takes text
parameter. How do I pass title
parameter as additional parameter from methodA to methodB ?
function methodA(link,title){
return superagent.get(link).then(page => page.text).then(methodB); <== here
}
function methodB(text,title) {
const promotions = [];
const html = cheerio.load(text);
html("#promolain > li > a > img").each((index, element) => {
//console.log("scraping promo : "+element.attribs.title);
promotions.push(element.attribs);
});
return promotions;
}
You can use a fat arrow function:
function methodA(link,title){
return superagent.get(link)
.then(page => page.text)
.then(text => methodB(text, title));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.