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