This example for you to share the Nodejs Crawler to obtain data code for your reference, the specific contents are as follows
var http=require (' http ');
var cheerio=require (' Cheerio ');/page Gets the data module var url= ' http://www.jcpeixun.com/lesson/1512/'; The function Filterdata (HTML) {/* is the destination array to get the Var coursedata=[{chaptertitle: "", videosdata:{Videotitle:tit
Le, 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 V
ideotitle=$ (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) {CONSOL
E.log (item.chapterstitle+ ' \ n '); Item.videosData.forEach (function (item) {Console.log (item.title+ ' ' +item.id+ ' "' +item.price+ ')})} HTTP.G
ET (url,function (res) {html= "";
Res.on ("Data", function (data) {html+=data}) Res.on (' End ', function () {var coursedata=filterdata (HTML);
Printcourseinfo (Coursedata)})})
Effect Chart:
The above is the Nodejs crawler to obtain data related code, hope for everyone's learning help.