NodeJS 获取网页源代码

node 获取网页源代码


  var http = require('http');
  var url = "http://www.baidu.com/";
  // 参数url 和 回调函数
  http.get(url,function(res){
      var html = '';
      // 绑定data事件 回调函数 累加html片段
      res.on('data',function(data){
          html += data;
      });

      res.on('end',function(){
          console.log(html);
      });
  }).on('error',function(){
      console.log('获取数据错误');
  });

猜你喜欢

转载自www.cnblogs.com/daysme/p/9109214.html