var steps=[];
var testindex = 0;
var loadInProgress = false;//This is set to true when a page is still loading
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.loadImages = false;//Script is much faster with this field set to false
phantom.cookiesEnabled = true;
phantom.javascriptEnabled = true;
console.log('All settings loaded, start with execution');
page.onConsoleMessage = function(msg) {
console.log(msg);
};
steps = [
function(){
console.log('Step 1 - Open Fb home page');
page.open("https://www.facebook.com/login.php", function(status){
});
},
function(){
console.log('Step 3 - Populate and submit the login form');
page.evaluate(function(){
document.getElementById("email").value="[email protected]";
document.getElementById("pass").value="xxx";
document.getElementById("login_form").submit();
});
},
function() {
page.render('homepage.png');
},
function(){
page.open("https://www.facebook.com/settings", function(status){
});
},
function() {
page.render('settings.png');
},
];
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();
}
}
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);
};
Wie "https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" injizieren und verwendetWie injiziere ich jquery (js) in Phantomjs?
$('#email').attr("value", "[email protected]");
$('#pass').attr("value", "xxxx");
$('#login_form').submit();
Ich versuche, alle Methode, aber Skript kann nicht arbeiten.
Ich sehe nicht, wo Sie versucht haben, jQuery in Ihrem Code zu verwenden. Bitte bearbeiten Sie Ihre Frage, um den tatsächlichen Code anzuzeigen. Woher weißt du, dass es nicht funktioniert? Haben Sie auf eine bestimmte Zeit gewartet? Hast du Screenshots gemacht? –