response.setHeader('content-type', 'text/html;charset=utf-8'); response.writeHead(200, {"Content-Type": "text/plain"}); var options = { host: '10.211.55.5', port: 8006, path: '/detail' }; var html = '追加变量的变量 '; http.get(options, function(res) { res.on('data', function(data) { console.log("data here = " + data); // collect the data chunks to the variable named "html" html += data; html += "这里在获取数据"; }).on('end', function() { // the whole of webpage data has been collected. parsing time! var title = $(html).find('div h3 span').each(function($this){ var a = $(this).children('a').attr('href'); var b = $(this).children('a').text(); console.log(b + ":" + options.host + a); html += b + ":" + options.host + a; response.write(html); }); html += "这里在循环数据"; }); html += '结束'; }); response.end(); }
执行上面的方法,在nodejs里面需要加入几个模块
1 2 3 4
var querystring = require("querystring"); var fs = require("fs"); var http = require('http'); var $ = require('jquery');