I've been trying any solutions i've found on the internet but unfortunately nothing works yet.These are some of the solutions from these links https://github.com/puppeteer/puppeteer/issues/4871https://github.com/puppeteer/puppeteer/issues/4732i'm just starting with puppeteer so i don't know what's the problem. I've read that google sort of blocks this kind of scripts.I've tried 2 different solutions based on what i've searched but nothing works yet.Attempt 1: ``` const puppeteer = require('puppeteer-extra'); const StealthPlugin = require('puppeteer-extra-plugin-stealth');puppeteer.use(StealthPlugin());const dotenv = require('dotenv');dotenv.config();async function run() { const browser = await puppeteer.launch({ headless: false, slowMo: 50, });const page = await browser.newPage(); await page.goto('http://accounts.google.com');const navigatePage = page.waitForNavigation();const email = 'input[type="email"]'; const password = 'input[type="password"]';await page.waitForSelector(email); await page.type(email, process.env.EMAIL); await Promise.all([page.keyboard.press('Enter')]);await page.waitForSelector(password); await page.type(password, process.env.PASS); await Promise.all([page.keyboard.press('Enter'), navigatePage]);await page.screenshot({ path: 'testresult.png' }); await browser.close(); }run(); ```This one is another solution that i did: attempt #2 ``` const puppeteer = require('puppeteer'); // const puppeteer = require('puppeteer-extra'); // const pluginStealth = require('puppeteer-extra-plugin-stealth'); // puppeteer.use(pluginStealth()); const chromeLauncher = require('chrome-launcher'); const axios = require('axios'); const Xvfb = require('xvfb');const xvfb = new Xvfb(); xvfb.startSync(); const chromeConfig = { // chromePath: '/usr/bin/google-chrome', userDataDir: '/home/chan-dev/.config/google-chrome/Default', };async function launch() { const chrome = await chromeLauncher.launch(chromeConfig); console.log({ chrome }); const response = await axios.get( http://localhost:${chrome.port}/json/version ); const { webSocketDebuggerUrl } = response.data;const browser = await puppeteer.connect({ browserWSEndpoint: webSocketDebuggerUrl, });const page = await browser.newPage(); await page.goto('http://accounts.google.com');const navigatePage = page.waitForNavigation();const email = 'input[type="email"]'; const password = 'input[type="password"]';await page.waitForSelector(email); await page.type(email, process.env.EMAIL); // await Promise.all([page.keyboard.press('Enter')]); await page.keyboard.press('Enter');await page.waitForSelector(password); await page.type(password, process.env.PASS); // await Promise.all([page.keyboard.press('Enter'), navigatePage]); await page.keyboard.press('Enter');await page.screenshot({ path: 'testresult.png' }); await browser.close(); }launch() .then(() => console.log('ok')) .catch(err => console.error(err)); ```
Submitted June 25, 2020 at 10:52AM by theUnknown777
No comments:
Post a Comment