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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

用cheerio寫(xiě)小爬蟲(chóng),跑程序無(wú)反應(yīng)

用cheerio寫(xiě)小爬蟲(chóng),跑程序無(wú)反應(yīng)

吃天狗的月亮 2017-05-26 16:21:46
var?http?=?require('http'); var?cheerio?=?require('cheerio'); var?url?=?"http://idcbgp.cn/learn/348"; function?filterChapters(html){ ???var?$?=?cheerio.load('html'); ???var?chapters?=?$('.chapter'); ???var?courseData?=?[]; ???chapters.each(function(item){ ???????var?chapter?=?$(this); ???????var?chapterTitle?=?chapter.find('strong').text(); ???????var?videos?=?chapter.find('.video').children('li'); ???????var?chapterData?=?{ ???????????chapterTitle:?chapterTitle, ???????????videos:?[] ???????} ???????videos.each(function(item){ ???????????var?video?=?$(this).find('.J-media-item'); ???????????var?videoTitle?=?video.text(); ???????????var?id?=?video.attr('href').split('video/')[1]; ???????????chapterData.videos.push({ ???????????????id:?id, ???????????????title:?videoTitle ???????????}); ???????}) ???????courseData.push(chapterData); ???}) ????return?courseData; } function?printCourseInfo(courseData)?{ ????courseData.forEach(function(item){ ????????var?chapterTitle?=?item.chapterTitle; ????????console.log(chapterTitle+'\n'); ????????item.videos.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); ???}) }).on('error',?function?()?{ ???console.log('獲取課程信息出錯(cuò)!') })這是源碼,不知道哪里出錯(cuò)了,代碼就是不執(zhí)行,不知道是因?yàn)閏heerio安裝問(wèn)題還是代碼問(wèn)題,試了各種網(wǎng)上的方法都沒(méi)用?。?!
查看完整描述

2 回答

?
吃天狗的月亮

TA貢獻(xiàn)3條經(jīng)驗(yàn) 獲得超1個(gè)贊

問(wèn)題已解決,在第六行的代碼中???var?$?=?cheerio.load('html');

應(yīng)該是???var?$?=?cheerio.load(html);

查看完整回答
反對(duì) 回復(fù) 2017-06-07
?
拿不到鑰匙的車(chē)放不進(jìn)手機(jī)的歌

TA貢獻(xiàn)71條經(jīng)驗(yàn) 獲得超29個(gè)贊

函數(shù)沒(méi)調(diào)用?

查看完整回答
反對(duì) 回復(fù) 2017-05-26
  • 2 回答
  • 0 關(guān)注
  • 1479 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)