在 Playwright 中禁用 Javascript

Disable Javascript in Playwright

是否可以定义禁用 Javascript 的浏览器来模拟爬虫如何查看页面?应该有个选项可以通过。

您可以在 BrowserContext 选项中传递 javaScriptEnabled

const playwright = require("playwright");

(async () => {
  const browser = await playwright.chromium.launch();
  const context = await browser.newContext({
    javaScriptEnabled: false
  });
  const page = await context.newPage();
  // ...
  await browser.close();
})();