Open
Description
我在做《Node.js 包教不包会》系列里面 lesson4的挑战题,取“积分”的时候,遇到一个难点,不知道怎样用superagent里面取到的变量取修改外面的全局变量,代码(部分)如下:
var topicUrl = topicPair[0];
var topicHtml = topicPair[1];
var $ = cheerio.load(topicHtml);
//取评论人的积分
var authorUrl = url.resolve(cnodeUrl,$('.dark.reply_author').eq(0).attr('href'));
let score1 =0;
superagent.get(authorUrl)
.end(function (err, sres) {
// 常规的错误处理
if (err) {
return next(err);
}
const $2 = cheerio.load(sres.text);
score1 = $2('.unstyled .big').eq(0).text().trim();
console.log("In ,score1:"+score1);
})
return ({
title: $('.topic_full_title').text().trim(),
href: topicUrl,
comment1: $('.reply_content').eq(0).text().trim(),
author1: $('.dark.reply_author').eq(0).text().trim(),
score1: score1
});
superagent里面的score1已经取到积分了,但没办法传出来。。。谢谢
Metadata
Metadata
Assignees
Labels
No labels