как нажать на кнопку входа в систему с помощью Phantomjs - PullRequest
0 голосов
/ 31 марта 2020

Я использую этот код:

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 (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.resourceTimeout   = 500000; 
page.settings.loadImages        = false; //Script is much faster with this field set to false
phantom.cookiesEnabled          = true;
phantom.javascriptEnabled       = true;
var fs                          = require('fs');
var CookieJar                   = "cookiejar.json";
/*********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 login page
    function(){
        console.log('Step 1 - Openlogin page');
        page.open("https://intracomone.com/customer/account/login/", function(status){          
        });     
    },
    //Step 2 - Populate and submit the login form
    function(){
        console.log('Step 2 - Populate and submit the login form');
        page.evaluate(function(){
            document.querySelector('input[name="login[username]"]').value="X"; 
            document.querySelector('input[name="login[password]"]').value="X";  
            document.forms[1].submit();  

        });
        page.render("page1.png");
    },
    //Step 3 - Redirect to page we pass throught the php, after login
    function(){

            console.log('Step 3 - Redirect to certain page');
            page.open('https://intracomone.com/customer/account/index/', function(status) { // args[1] is the url of the page that we are redirected
                    console.log(page.content);
                    page.render("page.png");
                    phantom.exit();
            });
    }
];
/********** END STEPS THAT FANTOM SHOULD DO  ***********************/

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

function executeRequestsStepByStep(){
    if (loadInProgress == false && typeof steps[testindex] == "function") {        
        steps[testindex]();
        testindex++;
    }
}

/**
 * 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);
};

Я хочу войти на этот сайт:

https://intracomone.com/

Я пытался сохранить скриншоты страниц до и после нажатия кнопки и они одинаковы, так что ошибка в этой части кода:

//Step 2 - Populate and submit the login form
function(){
    console.log('Step 2 - Populate and submit the login form');
    page.evaluate(function(){
        document.querySelector('input[name="login[username]"]').value="X"; 
        document.querySelector('input[name="login[password]"]').value="X";  
        document.forms[1].submit();  

    });
    page.render("page1.png");
},

Это что-то об этой кнопке отправки, я думаю, что скрипт действительно нажимает на кнопку входа в систему, и поэтому я не могу войти, какая-либо помощь?

...