gpt4 book ai didi

node.js - puppeteer page.authenticate https 代理不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 01:42:46 25 4
gpt4 key购买 nike

运行 puppeteer 时代理身份验证失败。

Puppeteer 版本:1.8

平台/操作系统版本:MacOS 10.13.6

Node.js版本:v10.9.0

    const puppeteer = require('puppeteer');

(async () => {
const browser = await puppeteer.launch({
headless:false,
ignoreHTTPSErrors:true,
devtools:true,
timeout:3000,
args: ['--no-sandbox','--proxy-server=xxx:xxx']
});
const user='xxx';
const password='xxx';
const page = await browser.newPage();
// await page.setExtraHTTPHeaders({
// 'Proxy-Authorization': 'Basic ' + Buffer.from(`${user}:${password}`).toString('base64'),
// });
await page.authenticate({username:user, password:password});
await page.goto('https://www.apple.com/');
let title = await page.title();
console.log("title:" + title);
await browser.close();
})();

出现错误:

(node:5858) UnhandledPromiseRejectionWarning: 
Error: net::ERR_TUNNEL_CONNECTION_FAILED at https://www.apple.com/
at navigate (/xxx/node_modules/_puppeteer@1.8.0@puppeteer/lib/Page.js:622:37)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:5858) UnhandledPromiseRejectionWarning:
Unhandled promise rejection. This error originated either by throwing
inside of an async function without a catch block,
or by rejecting a promise which was not handled with .catch().
(rejection id: 1)

最佳答案

const puppeteer = require('puppeteer');

(async () => {
const browser = await puppeteer.launch({
headless:false,
ignoreHTTPSErrors:true,
devtools:true,
timeout:3000,
args: ['--no-sandbox','--proxy-server=https=xxx:xxx']
});
const user='xxx';
const password='xxx';
const page = await browser.newPage();
await page.authenticate({username:user, password:password});
await page.goto('https://www.apple.com/');
let title = await page.title();
console.log("title:" + title);
await browser.close();
})();

对我来说,它是通过在代理服务器参数之间添加 https 来实现的。

关于node.js - puppeteer page.authenticate https 代理不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52368847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com