注意: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);
})
})