ubuntu - 有没有办法在 Puppeteer for Firefox 中使用代理?

标签 ubuntu firefox web-crawler puppeteer http-proxy

有没有办法将 Puppeteer 配置为在 Firefox 中使用代理,而无需手动调整我的操作系统的代理设置?

我可以在 Chrome 中通过使用命令行参数 args: [ '--proxy-server=http://0.0.0.0:0000' ] 来完成此操作,但 Firefox 没有'好像没有这个能力。

最佳答案

很遗憾,Firefox 中没有“代理服务器”参数。

但是,您可以拦截请求并使用 puppeteer-proxy 设置代理。图书馆。

这里是 example .

import puppeteer from 'puppeteer';
import { proxyRequest } from 'puppeteer-proxy';

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  await page.setRequestInterception(true);

  page.on('request', async (request) => {
    await proxyRequest({
      page,
      proxyUrl: 'http://127.0.0.1:3000',
      request,
    });
  });

  await page.goto('http://gajus.com');
})();

它也适用于 Chrome 和 Firefox。

关于ubuntu - 有没有办法在 Puppeteer for Firefox 中使用代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62648045/

相关文章:

html - 如何在 Firefox 中隐藏 <input type ="date"> 的弹出日历?

在不同 Linux 版本上运行的 Python 可执行文件

ubuntu - Kubernetes pod 永远不会准备好

ubuntu - Windows 10 中 Ubuntu 中的 tkinter。错误 : "no display name and no $DISPLAY environment variable"

python - 如何使用 beautifulsoup 在下拉列表中获取选定的值?

python - 使用 iframe 抓取网站

sql - 爬虫/爬虫的数据库是什么?

ubuntu - Mercurial 通过 ssh,未找到存储库

html - Chrome /火狐 : Latest versions with major HTML5/CSS3 improvements?

html - Firefox 与 Chrome 的 Flexbox 区别?