简体   繁体   English

我可以从node.js服务器运行客户端url吗?

[英]Can I run a client-side url from the node.js server?

I need to mimic the user for some logging/caching purposes. 我需要为某些日志记录/缓存目的模拟用户。 I'd like to run a client-side url from the server. 我想从服务器运行客户端URL。

I looked into 我看着

var options = {
    host: 'myhost.com',
    path: '/myfile.html',
    method: 'GET'
};

var req = http.request(options, function(res) {
   //...
});
req.end();

but this would just get the .html file contents as opposed to actually running it. 但这只会获取.html文件的内容,而不是实际运行它。

What I'd like to do is actually run it, the way the user does when he types in the url (this html file in turns does various ajax calls to other servers). 我想做的实际上是运行它,即用户键入url时的方式(此html文件又对其他服务器进行了各种ajax调用)。 But is there a way to initiate this from my server? 但是有没有办法从我的服务器启动它? Perhaps even call a shell command that acts like the browser where I just pass in a url? 也许甚至调用行为类似于浏览器的shell命令(我只是在其中传递url)?

I achieved what I wanted by downloading a linux binary for phantomjs 1.9.2: https://code.google.com/p/phantomjs/downloads/list 通过下载适用于phantomjs 1.9.2的Linux二进制文件,我实现了所需的功能: https : //code.google.com/p/phantomjs/downloads/list

note that 1.9.2 has some limitations (I needed to polyfill the bind() command), 2.0 is good but they don't have a linux binary for it. 请注意,1.9.2有一些限制(我需要对poly()命令进行polyfill),2.0很​​好,但是他们没有linux二进制文件。 so people are waiting for 2.1 to come out. 因此人们正在等待2.1的问世。

I then run this binary from node.js with a url parameter. 然后,我使用url参数从node.js运行此二进制文件。

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

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