0

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.

This question differentiates from a similar question because his bug was that his phantom.exit() was not called correctly. I simply don't call it at all.

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);
    }
}
Iluvpresident
  • 163
  • 1
  • 15
  • My answer on the question I closed this as a duplicate doesn't just describe the *exit* issue which your code indeed doesn't have, but rather gives a concrete example of opening multiple pages one after the other, which should answer your question. – Artjom B. Apr 18 '16 at 20:13
  • Perhaps [Using Multiple page.open in Single Script](http://stackoverflow.com/questions/16996732/using-multiple-page-open-in-single-script) is a better duplicate target. – Artjom B. Apr 18 '16 at 20:18

0 Answers0