situation: want create multithread script load list of ips + account information csv. load data , call function open electron , run nightmare script in combination vo. inside script go site, loop through list of links , check if lives in australia. when have error, example timeout, browser stops working. error example ->
{ message: 'navigation error', code: -7, details: 'navigation timed out after 30000 ms', url: 'https://facebook.com/login' }
here code
var fs = require('fs'); var csv = require('fast-csv'); var vo = require('vo'); var nightmare = require('nightmare'); var count = 0; var urls = fs.readfilesync('uniqueids.csv').tostring().split("\n"); var arrayurls = object.keys(urls).map(function (key) {return urls[key]}); var bloqnumber = 0; function *run(proxy, user, pass, urlsid) { var nightmare = new nightmare({ webpreferences: { partition: 'your-custom-partition'}, switches:{ 'proxy-server': proxy, 'ignore-certificate-errors': true }, show: true }); yield nightmare .goto('https://facebook.com/login') .wait(".inputtext._55r1.inputtext._1kbt.inputtext._1kbt") .type('input[name="email"]', user) .type('input[name="pass"]', pass) .click('button[name=login]') .wait(29000); var range = urlsid * 2000; var rangestart = range - 2000; var urlsarray = arrayurls.slice(rangestart, range); (var = 0; < urlsarray.length; i++) { count++; console.log(count + " -> " + proxy); if (count > 150){ yield nightmare.end(); } yield nightmare .goto("https://www.facebook.com/profile.php?id=" + urlsarray[i] + "&sk=about§ion=living&pnref=about") .wait(1000); var seqcheck = yield nightmare.exists(".captcha_interstitial"); var bloqcheck = yield nightmare.exists(".mvl.ptm.uiinterstitial.uiinterstitiallarge.uiboxwhite"); if (seqcheck == true) { console.log("seqcheck"); yield nightmare.wait(29000); } if (bloqcheck == true) { console.log("blocked week" + user + proxy); bloqnumber++; console.log(bloqnumber); if (bloqnumber > 6) { yield nightmare.end(); } continue; } var location = yield nightmare.exists("._3pw9._2pi4._2ge8"); bloqnumber = 0; console.log(location); if (location == true) { var getlocation = yield nightmare.evaluate(function() { var jsonobject = new array(); var links = document.getelementsbyclassname('_3pw9 _2pi4 _2ge8'); var numprofiles = links.length; for(var = 0; i< numprofiles; i++){ var elem; try { elem = links[0].queryselector("._50f5._50f7 a").text; } catch (err) { var arrr = new array('hello', 'world'); return arrr; } jsonobject.push(elem); } return jsonobject; }); var locationstring = getlocation.join(" + "); console.log(locationstring + " -> " + urlsarray[i]); if (locationstring.indexof("australia") !== -1 || locationstring.indexof("queensland") !== -1 || locationstring.indexof("new south wales") !== -1 || locationstring.indexof("victoria") !== -1 || locationstring.indexof("northern territory") !== -1 || locationstring.indexof("south australia") !== -1|| locationstring.indexof("tasmania") !== -1 || locationstring.indexof("sydney") !== -1 || locationstring.indexof("adelaide") !== -1 || locationstring.indexof("cairns") !== -1 || locationstring.indexof("perth") !== -1 || locationstring.indexof("melbourne") !== -1 || locationstring.indexof("brisbane") !== -1 || locationstring.indexof("bundaberg") !== -1 || locationstring.indexof("canberra") !== -1 || locationstring.indexof("newcastle") !== -1 || locationstring.indexof("western australia") !== -1 ) { console.log("im in australia"); var stringtoprint = urlsarray[i] + ", " + locationstring + "\n"; fs.appendfile('pages.csv', stringtoprint.replace(/(\r\n|\n|\r)/gm,"") + "\n", function (err) { console.log("a new entry"); }); } } else { console.log("it false"); } } yield nightmare.end(); } fs.createreadstream('proxies.csv') .pipe(csv()) .on('data', function (data) { var proxy = data[0]; var user = data[1]; var pass = data[2]; var urlsid = data[3]; console.log(urlsid); console.log(user); console.log(pass); vo(run(proxy, user, pass, urlsid)).then(out => console.log('out', out)).catch(error => console.log(error)); }).on('end', function (data) { console.log('csv reading finished.') });
desired outcome: want every time kind of error thread closing.
solved. append .catch in example below.
yield nightmare .goto('https://facebook.com/login') .wait(".inputtext._55r1.inputtext._1kbt.inputtext._1kbt") .type('input[name="email"]', user) .type('input[name="pass"]', pass) .click('button[name=login]') .wait(29000).catch(function(err){ console.dir(err); nightmare.end(); });
Comments
Post a Comment