下面是我使用的代码:
proxy.js -
class Proxy
{
static create() {
return new Proxy();
}
this.browser = await puppeteer.launch({
args: [`--proxy-server=socks5:127.0.0.1:9150`, "--no-sandbox",
],
});
async newPage(newBrowser = false) {
/* Ensure a browser instance is present */
if (!this.browser) {
await this.launchNewBrowser();
}
/* Close all other pages/tabs */
await this.closePages();
}
connections.js (从这个文件调用)
const createTBrowser = require("..pathTo/proxy");
const Browser = createBrowser();
const page = await Browser.newPage();
await page.goto('Valid_URL');
发布于 2022-05-02 06:01:25
代理不起作用,因为pupeteer使用的是自签名证书,因此向args添加忽略标志可能会解决您的问题。
`class Proxy
{
static create() {
return new Proxy();
}
this.browser = await puppeteer.launch({
args: [`--proxy-server=socks5:127.0.0.1:9150`,
"--no-sandbox",
"--ignore-certificate-errors",
"--ignore-certificate-errors-spki-list" ,
],
});
async newPage(newBrowser = false) {
/* Ensure a browser instance is present */
if (!this.browser) {
await this.launchNewBrowser();
}
/* Close all other pages/tabs */
await this.closePages();
}`
https://stackoverflow.com/questions/72082746
复制相似问题