Entonces, en mi función web scraper, tengo las siguientes líneas de código:
let portList = [9050, 9052, 9053, 9054, 9055, 9056, 9057, 9058, 9059, 9060]; let spoofPort = portList[Math.floor(Math.random()*portList.length)]; console.log("The chosen port was " + spoofPort); const browser = await puppeteerExtra.launch({ headless: true, args: [ '--no-sandbox', '--disable-setuid-sandbox', '--proxy-server=socks5://127.0.0.1:' + spoofPort ]}); const page = await browser.newPage(); const userAgent = 'Mozilla/5.0 (X11; Linux x86_64)' + 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.39 Safari/537.36'; await page.setUserAgent(userAgent);Estoy tratando de rotar la dirección IP para cada solicitud (la función que contiene este código se llama esencialmente en cada solicitud de un cliente) para que el sitio web raspado no me bloquee tan rápido. Me sale el siguiente error:
2021-05-17T12:08:19.625349+00:00 app[web.1]: The chosen port was 9050 2021-05-17T12:08:20.042016+00:00 app[web.1]: Error: net::ERR_PROXY_CONNECTION_FAILED at https://expampleDomanPlaceholder.com 2021-05-17T12:08:20.042018+00:00 app[web.1]: at navigate (/app/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:115:23) 2021-05-17T12:08:20.042018+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:93:5) 2021-05-17T12:08:20.042019+00:00 app[web.1]: at async FrameManager.navigateFrame (/app/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:90:21) 2021-05-17T12:08:20.042020+00:00 app[web.1]: at async Frame.goto (/app/node_modules/puppeteer/lib/cjs/puppeteer/common/FrameManager.js:416:16) 2021-05-17T12:08:20.042021+00:00 app[web.1]: at async Page.goto (/app/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:819:16) 2021-05-17T12:08:20.042021+00:00 app[web.1]: at async /app/app.js:174:9Probé las soluciones detalladas en estas publicaciones, pero ¿quizás el problema sea con mi agente de usuario?:
Obtención de error al intentar usar el servidor proxy en Node.js/Puppeteer
https://github.com/puppeteer/puppeteer/issues/2472
ACTUALIZACIÓN: Traté de usar este paquete de compilación ( https://github.com/iamashks/heroku-buildpack-tor-proxy.git ) pero seguía causando que mi dinamómetro web se rompiera (se devolvió un error 'H14', lo que significa que usted tiene que borrar los paquetes de compilación y volver a agregarlos). No estoy seguro de cómo proceder desde aquí, ya que realmente parecía ser la única solución que pude encontrar.
Así que hay algunos problemas.
Error: net::ERR_PROXY_CONNECTION_FAILED at https://expampleDomanPlaceholder.comAquí hay un ejemplo de un servidor proxy en Camboya
We will use SOCKS4 proxy and IP location of this proxy at Cambodia. Proxy IP address 96.9.77.192 and port 55796 (not sure if it still works) const puppeteer = require('puppeteer'); (async () => { let launchOptions = { headless: false, args: ['--start-maximized', '--proxy-server=socks4://96.9.77.192:55796'] // this is where we set the proxy }; const browser = await puppeteer.launch(launchOptions); const page = await browser.newPage(); // set viewport and user agent (just in case for nice viewing) await page.setViewport({width: 1366, height: 768}); await page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'); // go to whatismycountry.com to see if proxy works (based on geography location) await page.goto('https://whatismycountry.com'); // close the browser await browser.close(); })(); #Proxy Issue If the proxy host requires AUTH then the example below would be more fitting. 'use strict'; const puppeteer = require('puppeteer'); (async () => { const username = process.env.USER const password = process.env.PASS const url = 'https://www.google.com' const browser = await puppeteer.launch({ # proxy host must be correct. args: [ '--proxy-server=socks5://proxyhost:8000', ], }); const page = await browser.newPage(); await page.authenticate({ username, password, }); await page.goto(url); await browser.close(); })(); this worked with tor. Tor ('--proxy-server=socks5://localhost:9050')Referencias: gracias a @Grant Miller por las pruebas de TOR.
https://dev.to/sonyarianto/practical-titiritero-usando-proxy-to-browse-a-page-1m82
¿Cómo hacer que el titiritero funcione a través del proxy de socks5?