Я хочу войти на этот сайт https://www.wm.com/us/ (вы можете видеть этот сайт, только если вы из США или имеете прокси-сервер США) Это страница входа
https://www.wm.com/us/en/mywm/locate?redirect=/us/en/mywm
Я написал скрипт в фантоме js, чтобы получить исходный код страницы с этой страницы, и он хорошо работает. Вот код:
var page = require('webpage').create();
page.onError = function(msg, trace) {
//prevent js errors from showing in page.content
return;
};
page.open("https://www.wm.com/us/en/mywm/locate?redirect=/us/en/mywm", function(status) {
setTimeout(function(){
console.log(page.content);
}, 10000);
});
Это важная часть из исходного кода:
> <form class="TextInputForm"><div class="TextInput
> widget-card-input"><input class="inputMaterial " type="email"
> maxlength="" placeholder="" id="loginEmail"><label class=""
> for="loginEmail">Email</label><div class="TextInput__error-message
> pt-2" style="min-height: 2.5rem;"><div
> class="validation-error"></div></div></div><div class="TextInput
> widget-card-input" style="margin-top: 1rem; margin-bottom:
> 0px;"><input class="inputMaterial password" type="password"
> maxlength="" placeholder="" id="loginPassword"><label class=""
> for="loginPassword">Password</label><button class="btn-right
> btn-right-ie" type="button" style="font-size: 14px; color: rgb(103,
> 105, 109); outline: none; cursor: pointer; position: relative; left:
> 0px; top: -0.4rem; transition: left 0.3s; -webkit-transition: left
> 0.3s;">SHOW</button><div class="TextInput__error-message pt-2" style="min-height: 2.5rem;"><div
> class="validation-error"></div></div></div><div class="mt-3"><div
> class="login-options-wrapper"><span class="forgot-link"><button
> class="link" type="button">Forgot
> password?</button></span></div><div><button class="Button a-taggable
> btn inter-font-weight-bold rounded-0 d-flex flex-column
> align-items-center justify-content-center ButtonPrimary text-uppercase
> px-5 my-3 ml-3" name="" type="submit" analytics="LOG IN" aria-label=""
> style="height: 3.125rem; font-size: 1rem;">LOG IN</button></div><div
> class="login-footer"><div class="login-copy">Already have an account
> or need to register?</div><button class="link register"
> type="button">Sign Up</button></div></div></form>
Теперь я хочу ввести пользователя, передать форму и отправить ее, чтобы я мог войти на веб-сайт, а затем на go на домашней странице и проверить, вошел ли я. Что касается формы, я добавил этот код:
var page = require('webpage').create();
var system = require('system');
var stepIndex = 0;
var loadInProgress = false;
email = "cc@cc.com";
password ="ccc";
page.onLoadStarted = function() {
loadInProgress = true;
console.log("load started");
};
page.onLoadFinished = function() {
loadInProgress = false;
console.log("load finished");
};
var steps = [
function() {
page.open("https://www.wm.com/us/en/mywm/locate?redirect=/us/en/mywm", function(status) {
page.evaluate(function(email, password) {
document.getElementsByClassName("inputMaterial ").value = email;
document.getElementsByClassName("inputMaterial password").value = password;
// document.getElementsByClassName("TextInputForm").click();
document.forms[0].submit();
console.log("Login submitted!");
}, email, password);
});
//page.render('output3.png');
},
function() {
page.render('output.png');
console.log("innerHTML: " + page.evaluate(function(){
return document.documentElement.innerHTML;
}));
console.log("full page: " + page.content);
},
function() {
phantom.exit();
}
]
setInterval(function() {
if (!loadInProgress && typeof steps[stepIndex] == "function") {
console.log("step " + (stepIndex + 1));
steps[stepIndex]();
stepIndex++;
}
if (typeof steps[stepIndex] != "function") {
console.log("test complete!");
phantom.exit();
}
}, 10000);
Проблема в том, что я не вставляю своего пользователя и не передаю его в форму, я проверил это через page.render и получил следующее изображение:
screenshoot
Итак, ошибка в этой части:
document.getElementsByClassName("inputMaterial ").value = email;
document.getElementsByClassName("inputMaterial password").value = password;
// document.getElementsByClassName("TextInputForm").click();
document.forms[0].submit();
Я вижу, что я сделал не так, любая помощь?