使用CasperJS登录亚马逊并处理Captcha [英] Login amazon using CasperJS with handling Captcha
本文介绍了使用CasperJS登录亚马逊并处理Captcha的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用PhantomJs和CasperJs登录亚马逊它工作正常,但是多次登录后亚马逊给了Captcha并且我的脚本失败了。如果它有验证码,我不知道如何处理登录脚本。这是我当前的代码,如果没有验证码,它可以正常工作。
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();
提前致谢。
推荐答案
亚马逊可能正在考虑各种用于显示验证码的事情。以下是我的观察结果。
Amazon may be considering various things for displaying captcha. Here is my observations.
我遇到过两种类型的亚马逊验证码。
I came across two types of amazon captchas.
- 基于浏览器的Captcha(在PhantomJS中可见。如果通过浏览器手动登录,则不可见。)
- 基于IP的Captcha。原因可能是请求太多。如果通过
浏览器手动登录,将显示验证码。
不知道如何解决第二个问题。请尝试以下建议来解决第一个问题。
Don't know how to solve the second issue. Try below suggestions for solving the first issue.
- 调用
phantomjs.exit()
在脚本的最后。
确保即使发生异常也会始终调用exit-method。 - 看来PhantomJS在退出时不会清除整个缓存。
在Ubuntu中,它将一些数据保存在目录〜/ .local / share / Ofi Labs / PhantomJS /
中。在运行脚本之前清除目录中的文件。
- Invoke
phantomjs.exit()
at the end of script. Make sure the exit-method will be invoked always even when exception occurred. - 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.
这篇关于使用CasperJS登录亚马逊并处理Captcha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文