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

问题描述

我对 PhantomJS 和编程还很陌生,所以请耐心等待.我正在尝试编写代码来登录我的亚马逊帐户,并将送货地址添加到我的地址簿中.我使用的代码在这里:

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 Login Scrape PhantomJS + CasperJS) 似乎也许有一些解决方案,但我在理解它时遇到了一些麻烦.任何人都可以用更通俗的术语解释如何在不从亚马逊遇到任何问题的情况下实现这一目标?

如果您不介意,还有一些其他问题:我正在我家本地运行此代码......那么我的 IP 地址现在是否在某些亚马逊"可疑 IP 列表"上?他们可以/会为此禁止我的帐户吗???我不想因为这样的事情而失去我的帐户. 也许我应该使用代理?有没有比 PhantomJS 更好的东西可以用于这个?

抱歉,我的问题很重,谢谢!

推荐答案

我认为亚马逊也通过图像发送 cookie.所以不要禁用图像加载.确保仅在页面完全加载后才从一个页面移动到另一个页面.以下是针对验证码问题的一些建议.

本文地址:https://www.itbaoku.cn/post/1740148.html