第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么我的大標題是一次全部列出?

var http=require('http');

var url='http://idcbgp.cn/learn/348';

var cheerio=require('cheerio');


function filterChapters(html){

var $=cheerio.load(html);

var chapters=$('div.chapter');

var courseData=[];


chapters.each(function(data){

var chapter=$(this);

chapter.find('.icon-info').remove();

var chapterTitle=$('.chapter strong').text().trim();

var videos=chapter.find('.video').children('li');

var videolist=[];

videos.each(function(item){

var video=$(this);

var videoall=video.find('.J-media-item');

var id=videoall.attr('href').split('video/')[1];

var videoTitle=videoall.find('.icon-video').remove().end().text().trim();


videolist.push({

title:videoTitle,

id:id

})

})

courseData.push({

title:chapterTitle,

courselist:videolist

});

})

return courseData;

}


function printCourseInfo(courseData){

courseData.forEach(function(item){

var chapterTitle=item.title;

console.log(chapterTitle+'\n');


item.courselist.forEach(function(video){

console.log('['+video.id+']'+video.title+'\n');

})

})

}


http.get(url,function(res){

var html='';


res.on('data',function(data){

html+=data;

})


res.on('end',function(){

var courseData=filterChapters(html);

printCourseInfo(courseData);

})


})

運行時內(nèi)容為:

一、前言

二、安裝nodejs

、、

五、、

然后才是1-1,,1-2


第二章的標題處也是五章標題都列出,再是2-1,2-2,,求解~


正在回答

2 回答

var chapterTitle=$('.chapter strong').text().trim();

bug在這兒,應更改為

var chapterTitle=chapter.$('strong').text().trim();

0 回復 有任何疑惑可以回復我~
#1

fel 提問者

非常感謝!
2016-11-14 回復 有任何疑惑可以回復我~

這是回調(diào)函數(shù)用法。數(shù),環(huán)

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
進擊Node.js基礎(一)
  • 參與學習       219315    人
  • 解答問題       982    個

本視頻教程帶你揭開Node.js的面紗,帶你走進一個全新世界

進入課程

為什么我的大標題是一次全部列出?

我要回答 關注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號