nodeJs爬蟲獲取數(shù)據(jù)簡單實現(xiàn)代碼
更新時間:2016年03月29日 17:27:29 作者:Jone_chen
這篇文章主要為大家詳細介紹了nodeJs爬蟲獲取數(shù)據(jù)簡單實現(xiàn)代碼,感興趣的小伙伴們可以參考一下
本文實例為大家分享了nodeJs爬蟲獲取數(shù)據(jù)代碼,供大家參考,具體內(nèi)容如下
var http=require('http'); var cheerio=require('cheerio');//頁面獲取到的數(shù)據(jù)模塊 var url='http://www.jcpeixun.com/lesson/1512/'; function filterData(html){ /*所要獲取到的目標數(shù)組 var courseData=[{ chapterTitle:"", videosData:{ videoTitle:title, videoId:id, videoPrice:price } }] */ var $=cheerio.load(html); var courseData=[]; var chapters=$(".list-collapse"); chapters.each(function(item){ var chapterTitle=$(this).find(".collapse-head").find("label").text(); var videos=$(this).find(".listview5").children("li"); var chaptersData={ chaptersTitle:chapterTitle, videosData:[] } videos.each(function(item){ var videoTitle=$(this).find(".ml10").attr('data-lesson-name'); var videoId=$(this).find(".ml10").attr('data-lesson-id'); var vadeoPrice=$(this).find(".colblue").text(); chaptersData.videosData.push({ title:videoTitle, id:videoId, price:vadeoPrice }) }) courseData.push(chaptersData) }) return courseData } function printCourseInfo(courseData){ courseData.forEach(function(item){ console.log(item.chaptersTitle+'\n'); item.videosData.forEach(function(item){ console.log(item.title+'【'+item.id+'】'+item.price+'\n') }) }) } http.get(url,function(res){ html=""; res.on("data",function(data){ html+=data }) res.on('end',function(){ var courseData=filterData(html); printCourseInfo(courseData) }) })
效果圖:
以上就是nodeJs爬蟲獲取數(shù)據(jù)的相關代碼,希望對大家的學習有所幫助。
您可能感興趣的文章:
- 手把手教你用Node.js爬蟲爬取網(wǎng)站數(shù)據(jù)的方法
- node.js讀取Excel數(shù)據(jù)(下載圖片)的方法示例
- 詳解使用Node.js 將txt文件轉為Excel文件
- Node.js利用js-xlsx處理Excel文件的方法詳解
- Node.js實現(xiàn)Excel轉JSON
- Nodejs實現(xiàn)爬蟲抓取數(shù)據(jù)實例解析
- nodejs爬蟲抓取數(shù)據(jù)之編碼問題
- nodejs爬蟲抓取數(shù)據(jù)亂碼問題總結
- Nodejs技巧之Exceljs表格操作用法示例
- 使用ExcelJS快速處理Node.js爬蟲數(shù)據(jù)
相關文章
Node中的util.promisify()方法的基本使用和實現(xiàn)
眾所周知,在JS中實現(xiàn)異步編程主要是通過以下幾種方案,回調(diào)函數(shù),觀察者模式,Generator,Promise,async / await ,今天就和大家一起聊一下在node中的一個util.promisify()這個API的基本使用和基本實現(xiàn)2023-07-07NodeJs crypto加密制作token的實現(xiàn)代碼
這篇文章主要介紹了NodeJs crypto加密制作token的實現(xiàn)代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-11-11使用npm命令提示: ''npm'' 不是內(nèi)部或外部命令,也不是可運行的程序的處理方法
這篇文章主要介紹了使用npm命令提示: 'npm' 不是內(nèi)部或外部命令,也不是可運行的程序,本文通過圖文并茂的形式給大家分享解決方案,需要的朋友可以參考下2020-05-05