Cookies弹出窗口阻止使用CasperJS登录亚马逊。

huangapple go评论56阅读模式
英文:

Cookies popup stops login to Amazon with CasperJS

问题

Cookies弹窗阻止使用CasperJS登录Amazon

我正在尝试使用CasperJS编写脚本以登录我的Amazon账户。截止到2023年,Amazon要求您首先输入电子邮件,然后加载一个新页面以输入密码。

我成功输入了我的电子邮件并点击"继续",但随后弹出了一个要求启用Cookies的弹窗:
查看截图

不幸的是,如您所见,没有"接受全部"的选项。

此外,在调试日志中,页面似乎已加载:

[debug] [phantom] :
 1. 针对选择器执行鼠标事件 'click': input#continue
 2. 步骤匿名 10/10 https://www.amazon.com/ap/signin?openid.pape.max_auth_age=0&openid.return_to=https://www.amazon.com/?ref_=nav_ya_signin&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&openid.assoc_handle=usflex&openid.mode=checkid_setup&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&openid.ns=http://specs.openid.net/auth/2.0& (HTTP 200)
3. 请求导航:url=https://www.amazon.com/ap/signin,类型=FormSubmitted,willNavigate=true,isMainFrame=true
4. url变更为"https://www.amazon.com/ap/signin"
5. 成功注入Casper客户端端实用程序
6. 步骤 _step 11/11 https://www.amazon.com/ap/signin (HTTP 200)

但当我尝试下载加载页面的内容时:

var html = this.getPageContent();
this.download(html, 'signin.html');

它显示给我一个错误页面的HTML源代码...

即使在没有输入电子邮件的情况下只是点击继续,我也会得到相同的错误。

我还尝试在PhantomJS上启用Cookies,像这样:

var casper = require('casper').create( {
    verbose: true, 
    logLevel: 'debug',
    userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36',
    pageSettings: {
        cookiesEnabled: true,
        loadImages: false,
        loadPlugins: false
    }
});

但它没有起作用。

是否有不同的方法来在PhantomJS上启用Amazon所需的Cookies,或绕过它,或其他方法?
如果我切换到Selenium并使用不同的无头浏览器,会有所帮助吗?

任何帮助将不胜感激。

英文:

Cookies pop-up stops login to Amazon with CasperJS

I am trying to write a script using CasperJS to login into my Amazon account.
As of now, in 2023, Amazon requires you to input the email first, and then it loads a new page for the password.

I managed to input my email and click "continue", however, right after that a pop appears that requires me to enable cookies:
see screenshot

Unfortunately, as you can see, there is no option to "accept them all".

Furthermore, in the debug log it seems the page was loaded:

[debug] [phantom] :
 1. Mouse event 'click' on selector: input#continue
 2. Step anonymous 10/10 https://www.amazon.com/ap/signin?openid.pape.max_auth_age=0&openid.return_to=https://www.amazon.com/?ref_=nav_ya_signin&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&openid.assoc_handle=usflex&openid.mode=checkid_setup&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&openid.ns=http://specs.openid.net/auth/2.0& (HTTP 200)
3. Navigation requested: url=https://www.amazon.com/ap/signin, type=FormSubmitted, willNavigate=true, isMainFrame=true
4. url changed to "https://www.amazon.com/ap/signin"
5. Successfully injected Casper client-side utilities
6. Step _step 11/11 https://www.amazon.com/ap/signin (HTTP 200)

But when I try downloading the contents of the loaded page like this:

var html = this.getPageContent();
this.download(html, 'signin.html');

it shows me the HTML source of an error page...

I get the same error even without inputting an email and just clicking continue.

I also tried to enable cookies on PhantomJS like this:

var casper = require('casper').create( {
    verbose: true, 
    logLevel: 'debug',
    userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36',
    pageSettings: {
        cookiesEnabled: true,
        loadImages: false,
        loadPlugins: false
    }
});

but it didn't work.

Is there a different way to enable the required cookies on PhantomJS for Amazon, bypass it, or something else?
If I change to Selenium and use a different headless browser could it help?

Any help would be appreciated.

######################################################################################

Here's the rest of my code for reference (don't worry, I'll replace it with a link once I have my Git repository set up to make the question shorter):

Casper.start('https://www.amazon.com/', function() {
  // Wait for the page to load
  this.waitForSelector('#nav-link-accountList', function() {
    // Click on ....
    this.click('#nav-link-accountList');
  });
});

var email = "my email";
var pass = "test"; 

var email_field_id = '#ap_email';
var continue_button_id = 'input#continue';
var password_field_id = 'input#ap_password';
var submit_button_id = '#signInSubmit'

casper.then(function() {
  this.waitForSelector(email_field_id, function() {  
    this.sendKeys(email_field_id, email);
  });
});

casper.then(function() {
    this.wait(2000, function() {
        this.click(continue_button_id);
    });
});

casper.then(function() { 
    casper.wait(5000, function() {
        this.capture('login.png');
        var html = this.getPageContent();
        this.download(html, 'signin.html');
});

casper.run();

答案1

得分: 1

使用Selenium可能不是最令人满意的答案,但由于找不到解决方法,我尝试使用Selenium,15分钟解决了问题。

没有ReCAPTCHA(不是第一次),也没有Cookie错误。

底线是使用Selenium,效果更好。

英文:

Welp, it might not be the most satisfying answer, but since I couldn't find an answer to this problem, I tried using Selenium instead, and I solved it in 15 minutes.

No ReCAPTCHA (not the first time) and no cookies error.

Bottom line- Use Selenium. It's better.

huangapple
  • 本文由 发表于 2023年3月21日 02:29:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75794036-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定