亚马逊登录Phantom JS [英] Amazon Login Phantom JS

查看:210
本文介绍了亚马逊登录Phantom JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PhantomJS和程序设计方面还很陌生,所以请多多包涵.我正在尝试编写代码以登录到我的Amazon帐户,并将送货地址添加到我的地址簿中.我正在使用的代码在这里:

I’m pretty new at PhantomJS and programming in general, so please bear with me. I’m trying to write a code to login to my Amazon account, and add shipping addresses to my address book. The code I’m using is here:

var steps=[];
var loadInProgress = false;//This is set to true when a page is still loading

/*********SETTINGS*********************/


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*****************/

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://www.amazon.com/gp/css/account/address/view.html?ie=UTF8&ref_=myab_view_new_address_form&viewID=newAddress&", function(status){      
         });
     },

     //Fill out login info
     function(){
         console.log('Step 2 - Populate and submit the login form');
         page.evaluate(function(){
             document.getElementById("ap_email").value= "my email";
             document.getElementById("ap_password").value="my password";
             document.getElementById("signInSubmit").click();
         });
     },

     //Write out webpage
         function(){
             var fs = require('fs');
             var result = page.evaluate(function() {
                     return document.querySelectorAll("html")[0].outerHTML;
                 });
             fs.write('AmazonPage1.html',result,'w');

         },

     //Fill out shipping info
         function(){
             console.log('Step 3 - Populate and submit the shpping info');
             page.evaluate(function(){

                 document.getElementById("enterAddressFullName").value= "name";
                 document.getElementById("enterAddressAddressLine1").value="address";
                 document.getElementById("enterAddressCity").value="city";
                 document.getElementById("enterAddressStateOrRegion").value="state";
                 document.getElementById("enterAddressPostalCode").value="zip";
                 document.getElementById("enterAddressPhoneNumber").value="phone";

                 document.getElementById("myab_newAddressButton").click();
             });

     },

     //Write out webpage
         function(){
             var fs = require('fs');
             var result = page.evaluate(function() {
                     return document.querySelectorAll("html")[0].outerHTML;
                 });
             fs.write('AmazonPage2.html',result,'w');

         }

     ];
/**********END STEPS THAT FANTOM SHOULD DO***********************/



//Execute steps one by one
interval = setInterval(executeRequestsStepByStep,50); 

var testindex = 0;

function executeRequestsStepByStep(){
    if (loadInProgress == false && typeof steps[testindex] == "function" ) {
        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);
};

有时它可以工作,但是大多数时候我会收到验证码或来自亚马逊的消息,说请启用Cookies才能继续".这篇文章( Amazon Seller Central登录Scrape PhantomJS + CasperJS )似乎也许有一些解决方案,但我在理解它时遇到了一些麻烦.任何人都可以用一些比较通俗易懂的方式来解释如何做到这一点而又不会遇到来自亚马逊的任何问题吗?

Sometimes it works, but most of the time I get a captcha or a message from Amazon saying "Please Enable Cookies to Continue". This post (Amazon Seller Central Login Scrape PhantomJS + CasperJS) seems to maybe have some solution but I’m having a little trouble making sense of it. Can anyone explain in somewhat more lay terms how to accomplish this without getting any problems from Amazon?

如果您不介意的话,还有其他一些问题: 我正在家里从本地运行此代码…我的IP地址现在在某些Amazon可疑IP列表"上吗?他们可以/是否会为此禁用我的帐户? .也许我应该使用代理服务器?有什么比PhantomJS更好的东西吗?

Also a few other questions if you don’t mind: I’m running this code locally from my home… so is my IP address now on some Amazon "suspicious IP list"? Can/would they ban my account for this??? I’d hate to lose my account over something like this. Maybe I should use a proxy? Is there something better than PhantomJS to use for this?

对已加载的问题表示抱歉,谢谢!

Sorry for the loaded question and thanks!

推荐答案

我认为亚马逊也通过图像发送cookie.因此,请不要禁用图像加载.确保仅在页面完全加载后才从一页移动到另一页.这是有关验证码问题的一些建议.

I think amazon sends cookie via images too. So don't disable image loading. Make sure you are moving from one page to another only after the page loaded completely. Here is some suggestions for the captcha issue.

这篇关于亚马逊登录Phantom JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆