Sin más ADO, publicaré el código central para Node.js para obtener el contenido de la página HTML.
El código específico es el siguiente:
var http = require ("http"); var iconv = request ('iconv-lite'); var option = {hostname: "stockdata.stock.hexun.com", ruta: "/gszl/s601398.shtml"}; var req = http.request (opción, function (res) {res.on ("data", function (chunk) {console.log (iconv.decode (chunk, "gbk"));});}). on ("error", function (e) {console.log (e.message);}); req.end (););Echemos un vistazo al siguiente contenido web de NodeJs Crawl
función loadPage (url) {var http = request ('http'); var pm = new promise (function (resolve, rechazar) {http.get (url, function (res) {var html = '' '; res.on (' data ', function (d) {html += d.toString ()}); res.on (' end ', function () {resolve (html);});}). on ('error', function (e) {rechazar (e)});}); return pm;} loadPage ('http://www.baidu.com') .then (function (d) {console.log (d);});