Vote count:
0
I have created a script that login vk.com using phantomjs and then after logging in it should display the contents of my id in cmd but instead it displays the content of the signin page. I have tried many other solutions as well but nothing seems to work for me and there is no much information on internet as well. Their own documentation is not enough.
Here is my script:
var page = new WebPage(), testindex = 0, loadInProgress = false;
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.onLoadStarted = function() {
loadInProgress = true;
console.log("load started");
};
page.onLoadFinished = function() {
loadInProgress = false;
console.log("load finished");
};
var steps = [
function() {
//Load Login Page
page.open("http://vk.com/");
},
function() {
//Enter Credentials
page.evaluate(function() {
var arr = document.getElementsByClassName("quick_login_form");
var i;
for (i=0; i < arr.length; i++) {
if (arr[i].getAttribute('method') == "POST") {
arr[i].elements["email"].value="myemail@something.com";
arr[i].elements["pass"].value="password";
return;
}
}
});
},
function() {
//Login
page.evaluate(function() {
var arr = document.getElementsByClassName("quick_login_button");
var i;
for (i=0; i < arr.length; i++) {
if (arr[i].getAttribute('method') == "POST") {
arr[i].submit();
console.log("success");
return;
}
}
});
},
function() {
// Output content of page to stdout after form has been submitted
page.evaluate(function() {
console.log(document.querySelectorAll('html')[0].outerHTML);
});
}
];
interval = setInterval(function() {
if (!loadInProgress && typeof steps[testindex] == "function") {
console.log("step " + (testindex + 1));
steps[testindex]();
testindex++;
}
if (typeof steps[testindex] != "function") {
console.log("test complete!");
phantom.exit();
}
}, 50);
asked 1 min ago
Unable to fetch and console.log the content of the logged in page
Aucun commentaire:
Enregistrer un commentaire