无法与puppeteer一起使用代理。错误:抛出ERR_NO_SUPPORTED_PROXIES

Jat*_*att 6 javascript node.js puppeteer

如何使用puppeteer设置代理?我尝试了以下方法:

(async () => {
    const browser = await puppeteer.launch({
        headless: false,
        args: [
            '--proxy-server=http://username:password@zproxy.luminati.io:22225'
        ]
    });
    const page = await browser.newPage();
    await page.goto('https://www.whatismyip.com/');
    await page.screenshot({ path: 'example.png' });

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

但这不起作用,我得到消息:

Error: net::ERR_NO_SUPPORTED_PROXIES at https://www.whatismyip.com/
Run Code Online (Sandbox Code Playgroud)

在控制台上。如何正确使用代理?

我还尝试了以下方法:

const browser = await puppeteer.launch({
        headless: false,
        args: [
            '--proxy-server=zproxy.luminati.io:22225'
        ]
    });

 const page = await browser.newPage();

 page.authenticate({
        username: 'username',
        password: 'password'
 })

 await page.goto('https://www.whatismyip.com/');
Run Code Online (Sandbox Code Playgroud)

但结果相同。

0x4*_*672 16

Chrome 无法处理代理 URL 中的用户名和密码。使用的第二个选项page.authenticate应该有效

(async () => {
  const browser = await puppeteer.launch({
        headless: false,
        args: [
            '--proxy-server=zproxy.luminati.io:22225'
        ]
    });

 const page = await browser.newPage();

 // do not forget to put "await" before async functions
 await page.authenticate({        
        username: 'username',
        password: 'password'
 })

 await page.goto('https://www.whatismyip.com/');
 ...
})();
Run Code Online (Sandbox Code Playgroud)


Zil*_*ith 6

(async () => {
    // install proxy-chain  "npm i proxy-chain --save"
    const proxyChain = require('proxy-chain');

    // change username & password
    const oldProxyUrl = 'http://lum-customer-USERNAMEOFLUMINATI-zone-static-country-us:PASSWORDOFLUMINATI@zproxy.lum-superproxy.io:22225';
    const newProxyUrl = await proxyChain.anonymizeProxy(oldProxyUrl);

    const browser = await puppeteer.launch({
        headless: false,
        args: [
            '--no-sandbox',
            '--disable-setuid-sandbox',
            `--proxy-server=${newProxyUrl}`
        ]
    });

    const page = await browser.newPage();
    await page.goto('https://www.whatismyip.com/');
    await page.screenshot({ path: 'example.png' });

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