puppeteer添加代理
在使用puppeteer的时候添加代理的时候总是遇到 ERR_NO_SUPPORTED_PROXIES
(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(); })();
通过google找到正确的方法
(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(); })();
参考链接