【发布时间】:2020-10-31 20:51:31
【问题描述】:
过去 2 天我一直在尝试解决此问题,但未能成功。我到处都查过了,仍然没有解决方案。这是代码:
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());
const PROXY_SERVER_IP = 'IP.IP.IP.IP';
const PROXY_SERVER_PORT = '1234';
const PROXY_USERNAME = 'username';
const PROXY_PASSWORD = 'password';
(async () => {
const browser = await puppeteer.launch({
args: [`--proxy-server=http://${PROXY_SERVER_IP}:${PROXY_SERVER_PORT}`],
});
const page = await browser.newPage();
await page.authenticate({
username: PROXY_USERNAME,
password: PROXY_PASSWORD,
});
await page.goto('https://www.google.ca/', {
timeout: 0,
});
await page.screenshot({ path: 'test4.png', fullPage: true });
await browser.close();
})();
我在 page.goto() 调用上收到导航超时错误,因为它只是由于某种原因挂起。我不知道为什么。当我放置不需要身份验证的代理时,它可以工作。由于这个问题,我正在考虑切换到另一种无头解决方案,我非常感谢一些帮助。
【问题讨论】:
-
我知道剧作家至少有 chromium 和 firefox 的代理身份验证。
-
我认为问题在于设置http身份验证而不是代理身份验证。尝试使用地址:
http://user::password@ip:port,例如:http://leo:some%40password@192.168.15.80:3128(密码必须用encodeURIComponent编码),或者使用Proxy-Authenticationhttp header。看这里:github.com/puppeteer/puppeteer/issues/676 -
@pguardiario 感谢您的建议,我实际上是在看剧作家,可能会转行。
-
@Leo 我已经尝试过该标头解决方案,但没有奏效:/。当您说“问题在于设置 http 身份验证而不是代理身份验证”时,您能否扩展您的意思?
-
@pguardiario 好的,所以我刚刚用 Playwright 尝试了这个,我得到了完全相同的问题!我知道代理不是问题,因为我可以通过它向google.com 发出 cURL 请求,一切正常..
标签: authentication https proxy puppeteer headless-browser