如何使用 Goutte 登录 Amazon SellerCentral

How to login to Amazon SellerCentral using Goutte

有没有办法使用 Goutte 登录卖家中心? 我试过了,但它一直说密码错误(我手动尝试过,它工作正常):

$client = new Client();
$crawler = $client->request('GET', 'https://sellercentral.amazon.com');
$form = $crawler->selectButton('sign-in-button')->form();
$crawler = $client->submit($form, array('username' => 'test@test.com', 'password' => '123456'));

谢谢

弄清楚我不能用 Goutte 做到这一点,它太有限了。

将 phantomjs 与 casperjs 结合使用。

使用 Goutte 登录

require_once 'vendor/autoload.php';

use Goutte\Client;

$client = new Client();
$client->setHeader('User-Agent', "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:57.0) Gecko/20100101 Firefox/57.0");
$url = 'https://sellercentral.amazon.in/';

$crawler = $client->request('GET',$url );

$form = $crawler->selectButton('signInSubmit')->form();

$crawler = $client->submit($form, array('email' => 'your_email', 'password' => 'password'));

echo $crawler->html();

使用phantomjs登录

var steps = [];
var testindex = 0;
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 (Macintosh; Intel Mac OS X 10.13; rv:57.0) Gecko/20100101 Firefox/57.0';
page.settings.javascriptEnabled = true;
page.settings.loadImages = true;//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 https://sellercentral.amazon.in/
    function () {
        console.log('Step 1 - Open https://sellercentral.amazon.in/');
        page.open("https://sellercentral.amazon.in/", function (status) {

        });
    },

    //Step 2 - Enter Login details and submit form
    function () {
        console.log('Step 2 - Enter Login details and submit form');
        page.evaluate(function () {
            document.getElementById("ap_email").value = "YOUR_EMAIL_ID";
            document.getElementById("ap_password").value = "YOUR_PASSWORD";
            document.forms['signIn'].submit();
        });
    },


    //Step 2 - Final Step save page as html file. 
    function () {
        console.log("Step 3 - Final step");
        var fs = require('fs');
        var result = page.evaluate(function () {
            return document.querySelectorAll("html")[0].outerHTML;
        });
        fs.write('AmazonSellercentral.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("step " + (testindex + 1));
        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);
};