PhantomJS/CasperJS网站登录,PhantomJS不接受cookie [英] PhantomJS/CasperJS site login, cookies are not accepted by PhantomJS

查看:121
本文介绍了PhantomJS/CasperJS网站登录,PhantomJS不接受cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近尝试登录一个网站,强制我接受cookie.我正在使用phantomJs和casperJs.我写了一个应该处理登录的小脚本,但是它将我重定向到一个告诉我必须接受Cookie的站点.电子邮件和密码只是占位符.

I recently tried to login into a webiste that forces me to accept cookies. I'm using phantomJs and casperJs. I wrote a little script that should handle the login, but it redirects me to a site that tells me I have to accept cookies. Email and password are just placeholders.

我要登录的站点是https://de.buyvip.com/.但是我需要单击按钮Anmelden mit Amazon,以便可以使用我的亚马逊帐户登录.其他登录表单不起作用. (这导致了这个长网址,我只是从浏览器中复制了它)

The site I want to login is https://de.buyvip.com/. But I need to click the button Anmelden mit Amazon so I can login with my amazon account. The other login form does not work. (That leads to this long url, I just copied it from my browser)

有人可以帮助我吗?

这是脚本:

    var casper = require("casper").create()
    var fs = require('fs');
    var page = "https://www.amazon.de/ap/signin?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&pageId=quarterdeckde&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&clientContext=280-1158662-4507036&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&marketPlaceId=A38GABX06X24K&openid.assoc_handle=quarterdeckde&openid.return_to=https%3A%2F%2Fde.buyvip.com%2Fsignin&openid.pape.max_auth_age=0&siteState=http%3A%2F%2Fde.buyvip.com%2Fhomepage%3Fhash%3DM";

    phantom.cookiesEnabled = true;

    casper.start(page, function()
    {
        console.log("started");
        this.fill('form#ap_signin_form', {
            'email' : 'myMail',
            'password' : 'myPass'
        }, true);
    });

casper.then(function()
{
    fs.write("test.html", this.getHTML(), "w");
});

    casper.run();

推荐答案

也许稍后,但这就是答案:

Maybe a bit later, but this is the answer:

casper.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');

cookie失败,因为亚马逊不喜欢默认的Casper用户代理,在我的情况下:"Mozilla/5.0(Macintosh; Intel Mac OS X)AppleWebKit/534.34(KHTML,例如Gecko)CasperJS/1.0.2 + Phantomjs/1.7.0 Safari/534.34"

the cookies are failing because amazon doesn't like the default casper's user agent, in my case: "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) CasperJS/1.0.2+Phantomjs/1.7.0 Safari/534.34"

这篇关于PhantomJS/CasperJS网站登录,PhantomJS不接受cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆