아마존 앱 스토어로 Android 앱 제출을 자동화하는 PhantomJS 스크립트를 작성하려고합니다. 이 예제에서 스크립트를 작성하고 있습니다 : http://code-epicenter.com/how-to-login-amazon-using-phantomjs-working-example/. 이 예제에서 사용 된 URL 대신 https://developer.amazon.com/home.html을 사용하도록 예제를 수정했습니다. 내가 스크립트 출력이 AmazonLoggedIn.html 파일에 기록됩니까 실행하면PhantomJS 예제가 작동하지 않습니다.
var steps=[];
var testindex = 0;
var loadInProgress = false;//This is set to true when a page is still loading
/*********SETTINGS*********************/
var username = 'unknown';
var password = 'unknown';
var webPage = require('webpage');
var page = webPage.create();
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36';
page.settings.javascriptEnabled = true;
page.settings.loadImages = false;//Script is much faster with this field set to false
phantom.cookiesEnabled = true;
phantom.javascriptEnabled = true;
/*********SETTINGS END*****************/
/* Get command line args user password*/
var system = require('system');
var args = system.args;
if (args.length === 1) {
console.log('Try to pass some arguments when invoking this script!');
} else {
args.forEach(function(arg, i) {
console.log(i + ': ' + arg);
if (i === 1) { username = arg; }
if (i === 2) { password = arg; }
});
}
if (username == 'unknown') {
console.log('Please specify username and password');
phantom.exit();
}
if (password == 'unknown') {
console.log('Please specify username and password');
phantom.exit();
}
console.log('All settings loaded, start with execution');
page.onConsoleMessage = function(msg) {
console.log(msg);
};
/**********DEFINE STEPS THAT FANTOM SHOULD DO***********************/
steps = [
/*
* Step 1 - Open Amazon home page
*/
function(){
console.log('Step 1 - Open Amazon home page');
page.open("https://developer.amazon.com/home.html", function(status) {
console.log('status is '+ status);
});
},
/*
* Step 2 - Populate and submit the login form
*/
function(username,password){
console.log('Step 2 - Populate and submit the login form');
// var appActionToken = page.evaluate(function() { return $('input[name="appActionToken"]').attr('value'); });
// console.log('appActionToken is ' + appActionToken);
console.log('username is ' + username);
page.evaluate(function(username,password){
console.log(' username is ' + username);
document.getElementById("ap_email").value=username;
document.getElementById("ap_password").value=password;
document.getElementById("ap_signin_form").submit();
},username, password);
},
/*
* Step 3 - Wait Amazon to login user. After user is successfully logged in,
* user is redirected to home page. Content of the home page is saved to AmazonLoggedIn.html.
* You can find this file where phantomjs.exe file is. You can open this file using Chrome to ensure that you are logged in.
*/
function(){
console.log("Step 3 - blah blah blah");
var fs = require('fs');
var result = page.evaluate(function() {
return document.querySelectorAll("html")[0].outerHTML;
});
fs.write('AmazonLoggedIn.html',result,'w');
},
];
/**********END STEPS THAT FANTOM SHOULD DO***********************/
//Execute steps one by one
interval = setInterval(executeRequestsStepByStep,50);
function executeRequestsStepByStep(){
if (loadInProgress == false && typeof steps[testindex] == "function") {
console.log("testindex is " + testindex);
if (testindex == 1) {
console.log("username is " + username);
steps[testindex](username, password);
} else {
steps[testindex]();
}
testindex++;
}
if (typeof steps[testindex] != "function") {
console.log("test complete!");
phantom.exit();
}
}
/**
* These listeners are very important in order to phantom work properly.
* Using these listeners, we control loadInProgress marker which controls, weather a page is fully loaded.
* Without this, we will get content of the page, even a page is not fully loaded.
*/
page.onLoadStarted = function() {
loadInProgress = true;
console.log('Loading started');
};
page.onLoadFinished = function() {
loadInProgress = false;
console.log('Loading finished');
};
page.onConsoleMessage = function(msg) {
console.log(msg);
};
하지만 내용이 로그인이 실패했음을 나타냅니다 여기
내가 시도하는 것이다. 나는 정확한 신임장을 사용하고 있음을 확신합니다. 작동하지 않습니다 -
굉장합니다. 이고르에게 감사드립니다. 나는 당신의 해결책을 시험해보기 위해 오늘 시간을 갖기를 바랍니다. 내 브라우저에서 at_main, sess_at_main, session_id, ubid_main 및 x_main 값을 가져와야한다고 가정합니다. –
업데이트 : 로그인으로 지옥을 피하려면'--cookies-file' 옵션을 사용할 수 있습니다! 두 번째 시도 후에 스크립트는 매력처럼 작동합니다. './phantomjs --cookies-file = ./ cookies_2.txt your_script.js 이메일 패스>/dev/stdout' –
원본 스크립트를'--cookies-file' 옵션과 함께 사용하면 모두 작동합니다. 두 번째 시도 후,하지만 것입니다! –