The crawler of node. js

Source: Internet
Author: User

Nodejs crawl data problems with encoding errors

Can be processed using the Superagent-charset and superagent modules

var charset = require (' Superagent-charset '); var cheerio = require (' Cheerio '); var superagent = require (' superagent ') ; CharSet (superagent); var express = require (' Express '); var url = ' http://acm.hdu.edu.cn/statistic.php?pid=1000 '; var App = Express (); App.get ('/', function (req, res, next) {Superagent.get (URL). CharSet (' GBK '). End (Functio            N (err, sres) {var html = Sres.text;            var $ = cheerio.load (HTML, {decodeentities:false});            var len = $ ('. Table_text '). length;            Console.log (len);            var arr =[]; for (var i = 0; I<Len; i++)            {Arr.push ('. Table_text td a '). EQ (i). html ()); }//var ans= $ ('. Table_textTD a '). EQ (1). html ();            Res.send (ANS);            Res.send (arr);        Console.log (arr); });}); App.listen (+, function () {Console.log (' app is listening at Port ');});

The result is

The crawler of node. js

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.