gpt4 book ai didi

javascript - 如何在 puppeteer 和 headless Chrome 中使用代理?

转载 作者:数据小太阳 更新时间:2023-10-29 05:45:00 24 4
gpt4 key购买 nike

请告诉我如何在 puppeteer 和 headless Chrome 中正确使用代理。我的选择不起作用。

const puppeteer = require('puppeteer');
(async () => {
const argv = require('minimist')(process.argv.slice(2));

const browser = await puppeteer.launch({args: ["--proxy-server =${argv.proxy}","--no-sandbox", "--disable-setuid-sandbox"]});
const page = await browser.newPage();

await page.setJavaScriptEnabled(false);
await page.setUserAgent(argv.agent);
await page.setDefaultNavigationTimeout(20000);
try{
await page.goto(argv.page);

const bodyHTML = await page.evaluate(() => new XMLSerializer().serializeToString(document))
body = bodyHTML.replace(/\r|\n/g, '');
console.log(body);
}catch(e){
console.log(e);
}
await browser.close();
})();

最佳答案

您可以在 here 找到有关代理的示例

'use strict';

const puppeteer = require('puppeteer');

(async() => {
const browser = await puppeteer.launch({
// Launch chromium using a proxy server on port 9876.
// More on proxying:
// https://www.chromium.org/developers/design-documents/network-settings
args: [ '--proxy-server=127.0.0.1:9876' ]
});
const page = await browser.newPage();
await page.goto('https://google.com');
await browser.close();
})();

关于javascript - 如何在 puppeteer 和 headless Chrome 中使用代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52777757/

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