简体   繁体   中英

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.

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.

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). 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?

I achieved what I wanted by downloading a linux binary for phantomjs 1.9.2: 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. so people are waiting for 2.1 to come out.

I then run this binary from node.js with a url parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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