I am trying to open a public company page on Linkedin using Puppeteer, but every time it is redirected to an authentication form. This does not happen when I manually paste the URL in Chromium or in Chrome.
This is the code:
const puppeteer = require("puppeteer");
(async () => {
const url = "https://www.linkedin.com/company/google/";
const browser = await puppeteer.launch({
headless: false,
args: [
"--lang=en-GB",
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-gpu",
"--disable-dev-shm-usage",
],
defaultViewport: null,
pipe: true,
slowMo: 30,
});
const page = await browser.newPage();
await page.goto(url, {
waitUntil: 'networkidle0',
});
await page.waitForSelector(".top-card-layout__entity-info-container", { timeout: 10000 });
await page.close();
await browser.close();
})();
This is where the browser is redirected:
This does not happen if I manually paste the URL https://www.linkedin.com/company/google/
in Chromium or Chrome.
What I have tried so far:
- Use an
incognito
browser context:
// [...]
const context = await browser.createIncognitoBrowserContext();
const page = await context.newPage();
// [...]
- Use puppeteer-extra-plugin-stealth to avoid being detected as bot:
const puppeteer = require("puppeteer-extra");
puppeteer.use(require("puppeteer-extra-plugin-stealth")());
// [...]
const randomUserAgent = require("random-useragent");
// [...]
await page.setUserAgent(randomUserAgent.getRandom());
// [...]
Nothing has worked. Is there anything else I can try?