node.js - 将 PhantomJS 与/Node 一起使用并设置自定义用户代理

标签 node.js phantomjs

我在为我的虚拟页面设置自定义用户代理时遇到问题。我已经搜索了可能的解决方案,但我似乎缺少了它应该如何工作的一些基本部分,因为当我尝试设置我的设置时,我的幻像只是挂起并且没有完成请求或进入 page.open 方法。这是我的代码:

phantom.create().then(function(ph) {
     ph.createPage().then(function(page) {
       page.set('settings.userAgent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.256');
       page.open(req.cookies.website).then(function(status) {
         page.property('content').then(function(content) {
           res.send(content);
           page.close();
           ph.exit();
         });
       });
     });
   });

最佳答案

如果有人想知道,我解决了它......我只需要更仔细地查看 phantom npm 文档。如果其他人也遇到同样的问题,这里是解决方案:

phantom.create().then(function(ph) {
     ph.createPage().then(function(page) {
       page.setting('userAgent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.256');
       page.open(req.cookies.website).then(function(status) {
         page.property('content').then(function(content) {
           res.send(content);
           page.close();
           ph.exit();
         });
       });
     });
   });

关于node.js - 将 PhantomJS 与/Node 一起使用并设置自定义用户代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35514935/

相关文章:

node.js - Nodejs 通过套接字作为请求/响应服务器的客户端

ruby-on-rails - react_on_rails 安装 : yarn is required error

java - PhantomJSDriver 适用于 HTTP 但不适用于 HTTPS

javascript - Karma js 不会提供图片文件

phantomjs - 在指定路径找不到 phantomjs

linux - Phantomjs - 没有这样的文件或目录(我错过了什么)

node.js - 正确停止、等待和重置 node.js heroku 进程

javascript - Node.js http2 服务器与一个域的 http 服务器

html - API,将承载 token 传递到GET HTTP URL

javascript - SpookyJS:Console.log 在里面不起作用