在 Node.js 中加载 html 页面

And*_*Man 5 http node.js

如何使用 NodeJs 加载 HTML 页面?

maj*_*ann 5

此代码应从 html 页面加载数据。

var http = require('http');
http.get('http://www.google.com', onGotData);
function onGotData(res) {
  var chunks = [];
  res.on('data', onGotData);
  res.on('end', onEnd);
  function onGotData(chunk) {
    chunks.push(chunk);
  }
  function onEnd() {
    console.log(chunks.join(''));
  }
}
Run Code Online (Sandbox Code Playgroud)