Login amazon using CasperJS with handling Captcha

2019-02-15 14:57发布

问题:

I am using PhantomJs and CasperJs to login with amazon it works fine, however after multiple times login amazon gives Captcha and my script fails. I dont know how to handle login script if it has captcha. Here is my current code which works fine if no captcha.

var casper = require('casper').create();
var AMAZON_USER = 'amazon-username';
var AMAZON_PASS = 'amazone-password';

casper.start('https://www.amazon.com/gp/wallet', function () {

      this.echo('Loggin into amazon...');
      var emailInput = 'input#ap_email';
      var passInput = 'input#ap_password';

      this.mouseEvent('click', emailInput, '15%', '48%');
      this.sendKeys('input#ap_email', AMAZON_USER);

this.wait(3000, function () {
      this.mouseEvent('click', passInput, '12%', '67%');
      this.sendKeys('input#ap_password', AMAZON_PASS);
      this.mouseEvent('click', 'input#signInSubmit', '50%', '50%');
   });
});

casper.then(function (e) {
      this.capture('amazon.png');//print screen shot after login
});

casper.run();

Thanks in advance.

回答1:

Amazon may be considering various things for displaying captcha. Here is my observations.

I came across two types of amazon captchas.

  1. Captcha based on browser (Visible in PhantomJS side. Won't be visible if login via browser manually).
  2. Captcha based on IP. Reason can be too many requests. The captcha will be visible if login via browser manually.

Don't know how to solve the second issue. Try below suggestions for solving the first issue.

  1. Invoke phantomjs.exit() at the end of script. Make sure the exit-method will be invoked always even when exception occurred.
  2. It seems PhantomJS don't clear entire cache at exit. In Ubuntu, it saves some data in the directory ~/.local/share/Ofi Labs/PhantomJS/. So clear the files inside the directory before running the script.


回答2:

You can use the deathbycaptcha service to bypass the captcha.

They have very cheap price to solve the captchas.