app.get('/knowledge', function (req, res, next) { var listUid = req.query.listUid; var url = "http://www.lengdou.net/page/" + listUid + "/"; // console.log('--------开始检测--------'); var content = {}; var map = new Array(); superagent .get(url) .end(function (err, sres) { // callback // 常规的错误处理 if (err) { res.send('{\"code\":\"300\",\"msg\":\"读取出错!!\"}'); } try { var $ = cheerio.load(sres.text); var lists = $(".list").each(function (index, element) { var text = $(this).find(".list-content").find("p").text(); var url = $(this).find(".list-content").find("img").attr("src"); console.log(text + url + "\n"); var content = {}; content['text'] = text; content['url'] = url; map[index] = content; }); res.send(JSON.stringify(map)); } catch (e) { } });});