Nodejs Crawler to obtain data simple implementation code _node.js

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.