Reputation: 11
I am trying to use puppeteer to login to the nike site but I get an error likely due to anti-bot. I've tried some things to avoid being detected but did not have any luck. Here is my code:
//const puppeteer = require('puppeteer');
const puppeteer = require("puppeteer-extra");
const pluginStealth = require("puppeteer-extra-plugin-stealth");
puppeteer.use(pluginStealth());
//Create Sleep function to use in Async/Await function
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const randomDelay = (min, max) =>
Math.floor(Math.random() * (max - min + 1) + min);
(async () => {
await sleep(1000);
var browser;
browser = await puppeteer.launch({
executablePath: 'C:/Program Files/Google/Chrome/Application/chrome.exe',
headless: false,
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-web-security'],
});
const page = await browser.newPage();
await page.setUserAgent(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
);
await page.setExtraHTTPHeaders({
'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8',
});
await page.goto('https://www.nike.com/us/en_us/e/nike-plus-membership', {
waitUntil: 'networkidle0',
});
const emailSelector = '.nike-unite-text-input.emailAddress input';
await page.waitFor(emailSelector);
await page.waitFor(randomDelay(300, 600));
const inputs = [emailSelector, '.nike-unite-text-input.password input'];
await page.type(inputs[0], '[email protected]', {
delay: randomDelay(200, 300),
});
await page.waitFor(randomDelay(300, 600));
await page.type(inputs[1], 'XYZDEFEWD!"', {
delay: randomDelay(200, 300),
});
const submitBtn = '.nike-unite-submit-button.loginSubmit input';
await page.waitFor(randomDelay(200, 500));
await page.click(submitBtn);
})();
Is there any way to identify what the website is using to detect that I am using puppeteer?
Upvotes: 1
Views: 1733
Reputation: 814
There could be a full proof solution of avoiding bot detection, but here are the someways you can try
Try proxying your IP through multiple countries
Try to add random intervals in your n/w calls
use random user agents instead of fixed one and also alter the viewport size.
Upvotes: 2