const Nightmare = require('nightmare');
let proxyType = process.argv[2];
let proxyHost = process.argv[3];
let proxyPort = process.argv[4];
let proxyUser = process.argv[5];
let proxyPass = process.argv[6];
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
async function yourBot(url, proxyUser, proxyPass, proxyType, screenshot){
try{
var socks = '';
if(proxyType === "socks5" || proxyType === "socks4")
{
socks = proxyType + '://';
}
const nightmare = Nightmare({
show:true,
switches: {
'proxy-server': socks + proxyHost + ':' + proxyPort,
'ignore-certificate-errors': true
},
waitTimeout: 400000
});
nightmare.authentication(proxyUser, proxyPass);
await nightmare.cookies.clearAll();
await nightmare.useragent("Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.85 Safari/537.36");
const response = await nightmare.goto(url);
let waitTime = getRandomInt(10000,320000);
// wait some random time and wait or you could wait for some selector on the page
await nightmare.wait(waitTime);
if(screenshot != 0) {
await nightmare.screenshot('tmp/' + screenshot + '.png')
}
await nightmare.end(() => "Search bot done.");
}catch(err){
throw new Error(err)
}
}
yourBot('http://www.example.com/', proxyHost, proxyUser, proxyPass, proxyType, "sshot1").then(console.log).catch(console.log);