如何通过socks5代理让puppeteer工作?

Chu*_*nov 4 google-chrome headless headless-browser google-chrome-headless puppeteer

我买了socsk5的代理服务器版本。在所有手册中相同的例子

const browser = await puppeteer.launch({
    headless: true,
    ignoreHTTPSErrors: true,
    defaultViewport: {...winSize},
    args: [
        '--proxy-server=socks5://proxyhost:8000',
        '--host-resolver-rules="MAP * ~NOTFOUND , EXCLUDE proxyhost"',
    ],
})
Run Code Online (Sandbox Code Playgroud)

它没有为此代理指定登录密码,显然不起作用

如果你指定这个

'--proxy-server=socks5://user:password@proxyhost:8000',
Run Code Online (Sandbox Code Playgroud)

它给出了一个错误

net::ERR_NO_SUPPORTED_PROXIES

我尝试使用https://github.com/sjitech/proxy-login-automator构建一座桥,但它也不起作用。

请提示

Gra*_*ler 7

您可以使用page.authenticate()为您的代理提供凭据。

例如:

'use strict';

const puppeteer = require('puppeteer');

(async () => {
  const username = 'johndoe';
  const password = 'qwerty1';

  const browser = await puppeteer.launch({
    args: [
      '--proxy-server=socks5://proxyhost:8000',
    ],
  });

  const page = await browser.newPage();

  await page.authenticate({
    username,
    password,
  });

  await page.goto('https://www.example.com/');

  await browser.close();
})();
Run Code Online (Sandbox Code Playgroud)

  • 请注意,访问 HTTPS 页面时代理身份验证存在问题。https://github.com/puppeteer/puppeteer/issues/3253 您可能想尝试 https://github.com/gajus/puppeteer-proxy (3认同)