casper.js logon amazon

var LOGIN_URL, LOGIN_USERNAME, LOGIN_PASSWORD, casp;

casp = require('casper').create({
     viewportSize: {
          width: 1024,
          height: 768
     },
     verbose: true,
     logLevel: 'warning'
});
var fs = require('fs');

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

phantom.cookiesEnabled = true;
phantom.javascriptEnabled = true;

if (!casp.cli.has('username') && !casp.cli.has('password')) {
     casp.echo('Usage: $ casperjs sfdclogin.casper.js --username=USERNAME --password=PASSWORD [--prod]').exit(-1);
}

if (casp.cli.has('prod')) {
     LOGIN_URL = 'https://sellercentral.amazon.com/gp/sign-in/sign-in.html?destination=https%3A%2F%2Fsellercentral.amazon.com%2Fhz%2Fhome';
} else {
     LOGIN_URL = 'https://sellercentral.amazon.com/gp/sign-in/sign-in.html?destination=https%3A%2F%2Fsellercentral.amazon.com%2Fhz%2Fhome';
}

LOGIN_USERNAME = casp.cli.get('username');
LOGIN_PASSWORD = casp.cli.get('password');

casp.start(LOGIN_URL, function () {
     'use strict';
	// this.enableCookieSupport();
	// phantom.cookiesEnabled = true;
     this.log('Logging in', 'debug');
     
});

casp.then(function () {
     this.fill('form', {
          'username': LOGIN_USERNAME,
          'password': LOGIN_PASSWORD
     }, true);

     this.log('Logged in', 'debug');
});


casp.then(function () {
     'use strict';

     this.echo('We\'re logged in.  Now we can do more stuff like take a screenshot!');
     this.echo(this.getHTML());
});

casp.run();


执行:

casperjs --ssl-protocol=tlsv1 tt.js --username=dealschic@gmail.com  --password=zyz14607terr >> 22.html


下面是从屏幕键盘读取值,代码部分为:

this.echo("What is the ZIP code of the billing address you registered with your credit or debit card number that ends in 13?");
	zipcode = system.stdin.readLine();

var LOGIN_URL, LOGIN_USERNAME, LOGIN_PASSWORD, casp;

casp = require('casper').create({
     viewportSize: {
          width: 1024,
          height: 768
     },
     verbose: true,
     logLevel: 'warning'
});
var fs = require('fs');
var system = require('system');
	
		
casp.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');

phantom.cookiesEnabled = true;
phantom.javascriptEnabled = true;

if (!casp.cli.has('username') && !casp.cli.has('password')) {
     casp.echo('Usage: $ casperjs sfdclogin.casper.js --username=USERNAME --password=PASSWORD [--prod]').exit(-1);
}

if (casp.cli.has('prod')) {
     LOGIN_URL = 'https://sellercentral.amazon.com/gp/sign-in/sign-in.html?destination=https%3A%2F%2Fsellercentral.amazon.com%2Fhz%2Fhome';
} else {
     LOGIN_URL = 'https://sellercentral.amazon.com/gp/sign-in/sign-in.html?destination=https%3A%2F%2Fsellercentral.amazon.com%2Fhz%2Fhome';
}

LOGIN_USERNAME = casp.cli.get('username');
LOGIN_PASSWORD = casp.cli.get('password');

casp.start(LOGIN_URL, function () {
     'use strict';
	// this.enableCookieSupport();
	// phantom.cookiesEnabled = true;
     this.log('Logging in', 'debug');
     
});

casp.then(function () {
     this.fill('form', {
          'username': LOGIN_USERNAME,
          'password': LOGIN_PASSWORD
     }, true);

     this.log('Logged in', 'debug');
});


casp.then(function () {
	this.echo("What is the ZIP code of the billing address you registered with your credit or debit card number that ends in 13?");
	zipcode = system.stdin.readLine();
	
     this.fill('form', {
          'dcq_question_subjective_1': zipcode,
     }, true);

     this.log('Logged in', 'debug');
});


casp.then(function () {
     'use strict';

     this.echo('We\'re logged in.  Now we can do more stuff like take a screenshot!');
     this.echo(this.getHTML());
});

casp.run();



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值