注意:jQuery的map返回的对象是一个jQuery对象包装,需要通过get获得里面的值
var $ = cheerio.load(html); promiseList = $('#semester').children('option').filter().map((index, element) => { menu_options.path = constant.gread_path_prefix + gloable_variables.student_id + '?semester=' + $(element).attr('value')//TODO return new Promise(function (resolve, reject) {//获得学期列表 http.request(menu_options, function (res) { chunks = [] size = 0 res.on('data', function (chunk) { chunks.push(chunk); size += chunk.length; }); res.on('end', function () { buffer = Buffer.concat(chunks, size); zlib.gunzip(buffer, function (err, decoded) { resolve(decoded.toString()) }) }); }).end(); }) }).get() Promise.all(promiseList).then(function (resules) { resules.forEach(function (content_html) { var $ = cheerio.load(content_html); }) })