Как войти в Amazon SellerCentral с помощью 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' => '[email protected]', 'password' => '123456'));

Спасибо


person Lincoln    schedule 24.06.2016    source источник


Ответы (2)


Выясните, что я не могу сделать это с помощью Goutte, он слишком ограничен.

Использовал фантомы с касперами.

person Lincoln    schedule 13.07.2016

Войти с помощью 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);
};
person Nanhe Kumar    schedule 25.11.2017
comment
У вас есть идеи, как можно сделать ту же работу через php-phantom js? - person Parnit Das; 25.11.2017