繁体   English   中英

如何在node.js的帮助下使用站点在localhost上工作?

[英]How to use a site to work on localhost with the help of node.js?

我正在学习node.js,在其中尝试使用Google网页在本地主机上工作,该本地主机上的菜单项将被删除,但其搜索功能应在本地主机上工作,因为它在网站上可以正常工作。 这是我尝试在localhost上使用google的方法,但是在localhost上显示为“无法获取”,这是一种错误还是我做错了,请指导我如何实现我想要的工作。 我在XP上使用的是node.js ver5.9.1。

提前致谢。

search.js

var express = require('express'),   
        app = express();
var bodyParser = require('body-parser');
   compression = require('compression');   
var NLTunnel = require('node-local-tunnel');        
   var options = {

  remoteHost : 'http://www.google.com/',
  localBase : 'http://localhost:3000'
};
   NLTunnel.client(options);    

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
app.use(compression());
app.use(express.static('assets/'));

app.listen(3000);
    var express = require('express'),   
       app = express(),
       bodyParser = require('body-parser'),
       compression = require('compression'),
       http = require('http'),
       server = http.createServer(app);

    app.use(bodyParser());   
    app.use('/', express.static('public'));
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({extended:true}));
    app.use(compression());

    server.listen(3000);

尝试这个。 这正在我的机器上工作。

我尝试使用requestcheerio,但是我只得到html页面,没有任何cssjs页面(如果有),并且搜索功能也不起作用。 这是正确的工作方式,以及如何使搜索功能在localhost上正常工作。

var httpobj = require('http');
var request = require('request');
var cheerio = require('cheerio');
var all_html;
var url = 'https://www.google.co.in/?gfe_rd=cr&ei=dVHeVuLuG-uK8QeCk6vICw'

request(url, function (error, response, html) {
var $page = cheerio.load(html);
all_html = $page("html");    
}); 


httpobj.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});          
res.write(all_html + ' '); 
res.end('');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM