我正在尝试使用代理使用人偶浏览google.com,但Chromium似乎阻止了我。
代码示例:
const puppeteer = require('puppeteer');
(async() => {
const proxyUrl = 'http://gate.smartproxy.com:7000';
const username = 'xxxxx';
const password = 'xxxxx';
const browser = await puppeteer.launch({
args: [`--proxy-server=${proxyUrl}`],
headless: false,
});
const page = await browser.newPage();
await page.authenticate({ username, password });
await page.goto('https://google.com/');
const html = await page.$eval('body', e => e.innerHTML);
console.log(html);
await browser.close();
})();
错误:
(node:6673) UnhandledPromiseRejectionWarning: Error: net::ERR_TUNNEL_CONNECTION_FAILED at https://google.com/...
我已经检查了代理端,它们正在工作。
如果使用伪装者无法操作(因为他们使用的是Chromium),那么您对使用代理浏览Google有其他选择吗?
谢谢
答案 0 :(得分:0)
尝试用http替换https,并咨询代理服务,并查看其拥有的文件或可以提供的建议。或者,找出它是什么类型的代理,以及它通常的行为,并向我们提供更多信息。
答案 1 :(得分:0)
尝试使用 pluginProxy:
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
const pluginProxy = require('puppeteer-extra-plugin-proxy');
(async() => {
puppeteer.use(StealthPlugin()); // Recommende
puppeteer.use(pluginProxy({
address: <proxy-host> ,
port: <proxy-port> ,
credentials: {
username: <proxy-user> ,
password: <proxy-pwd> ,
}
}));
let browser = await puppeteer.launch({
headless: false,
ignoreHTTPSErrors: true // Some proxies need it
});
let page = await browser.newPage();
await page.goto('https://google.com/');
const html = await page.$eval('body', e => e.innerHTML);
console.log(html);
await browser.close();
})();