redirect - CasperJS 没有遵循重定向到 HTTPS

标签 redirect https casperjs

我正在尝试使用 CasperJS 来自动处理大量繁琐的数据输入。具体来说,要在佳能网站上注册非常大批量的相机设备。

我有处理表单填写的代码,并且使用 CasperJS 浏览网页没有问题,但我无法让 CasperJS 导航到登录页面。

这是我到目前为止所拥有的:

var casper = require('casper').create({
    verbose: true,
    userAgent: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36',
    logLevel: "debug"
});

phantom.cookiesEnabled = true;

casper.start();

casper.thenOpen('https://b2cweb.usa.canon.com/b2cweb/view/myAccountHome.jsf?LOGINACTION=Y', function(response) {
require('utils').dump(response);
});

casper.run();

注意:一旦到达页面,上面的代码就会转储标题内容。我还尝试了不同的用户代理字符串,以防 Adob​​e 主动阻止爬虫。

该链接在 Google Chrome 中完美运行,但 CasperJS 只记录以下内容。

Loading resource failed with status=fail



从 Google Dev Tools 看来,链接 302 重定向到

https://b2cweb.usa.canon.com/b2cweb/view/myAccountHome.jsf?LOGINACTION=Y



然后 301 重定向到:

https://b2cweb.usa.canon.com/b2cweb/view/login.jsf?TYPE=33554432&REALMOID=06-979697ef-63e3-49da-a97f-795f9d794fcc&GUID=&SMAUTHREASON=0&METHOD=GET&SMAGENTNAME=-SM-EA3lbvOPfpMVWEZ5fDNhRBdvP75YFZ%2fmmFcIOEdxcmO9f3eSAXAISOKvl7eaVyQm&TARGET=-SM-HTTP%3a%2f%2fb2cweb%2eusa%2ecanon%2ecom%2fb2cweb%2fview%2fmyAccountHome%2ejsf%3fLOGINACTION%3dY



我假设重定向是 CasperJS 无法获取登录页面的原因。

是否可以让 CasperJS 遵循这些类型的重定向? CasperJS 可以用于通过 HTTPS 浏览和/或登录吗?

更新:

我不太确定是否是导致问题的重定向。

作为一种解决方法,我尝试将 session cookie(从 chrome 复制)预加载到 casperjs,然后直接导航到帐户页面。

我还尝试将 --ignore-ssl-errors=true 标志添加到命令中,但没有成功。

无论我做什么,它都会返回一个 about:blank url。

最佳答案

以下将带您进入登录页面:

    var casper = require("casper").create ({
    waitTimeout: 15000,
    stepTimeout: 15000,
    verbose: true,
    viewportSize: {
        width: 1400,
        height: 768
    },
    onWaitTimeout: function() {
        logConsole('Wait TimeOut Occured');
        this.capture('xWait_timeout.png');
        this.exit();
    },
    onStepTimeout: function() {
        logConsole('Step TimeOut Occured');
        this.capture('xStepTimeout.png');
        this.exit();
    }
});

casper.on('remote.message', function(msg) {
    logConsole('***remote message caught***: ' + msg);
});

casper.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4');

// vars
var gUrl           = 'http://www.usa.canon.com/cusa/home';

// Open URL and click sign in
casper.start(gUrl, function() {
  this.clickLabel('Sign In', 'a');
});

//Sign in page
casper.then(function () {
  //+++ ready for you to fill user information.
  this.capture('xSignIn.png'); //+++ shows you are on signin page. can remove.
});

casper.run();

关于redirect - CasperJS 没有遵循重定向到 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19939062/

相关文章:

r - 使用 R 从带有登录凭据的 https 下载文件

javascript - 片段 uri 未在浏览器上执行

使用 RapidSSL 证书时 Node.js HTTPS 服务器没有响应

apache - OS X Mavericks 支持 SSL 的虚拟主机

casperjs - 你如何在 CasperJS 中禁用 css?

xpath - 所有 XPath 在 CasperJS 中都返回一个不存在的错误?

php - 如何在 Laravel 中做一个简单的重定向?

.htaccess - 旧页面 PR 到

http - 将 Heroku 子域请求重定向到另一个 IP

phantomjs - CasperJS 文件下载在 30 秒后超时