【问题标题】:Is it possible to script python3 selenium to automatically disable CSP for geckodriver?是否可以编写 python3 selenium 脚本来自动禁用 geckodriver 的 CSP?
【发布时间】:2021-02-10 03:02:41
【问题描述】:

我需要禁用 CSP,因为我可以通过打开 Firefox() Web 驱动程序,转到 about:config 并禁用:security.CSP.enable 来手动执行此操作。

我是 selenium 的新手,已经编写了我需要的所有东西,只是我需要自动禁用 CSP,我对木偶、功能和其他细节知之甚少。我只想自动禁用 CSP。可能吗?是否可以通过进行一些功能更改或通过:driver.get('about:config'); some code 或添加另一个扩展来实现?可能还有其他解决方案,比如下载没有 CSP 的 geckodriver,我找不到,或者如果它是开源的,甚至可以编译没有 CSP 的 geckodriver。

由于某种原因我不能使用 chromium,所以我需要在 Linux 中使用 geckodriver。

【问题讨论】:

    标签: python-3.x selenium firefox webdriver geckodriver


    【解决方案1】:

    一个小补充,为了在我的电脑(windows 10)上编译源代码,没有准备任何其他先决条件,我需要安装 rust 和 c++ 构建工具(c++ tools for rust

    【讨论】:

    【解决方案2】:

    这是最丑陋的方式,从源代码构建。步骤:

    • 火狐下载源:Firefox Source。然后解压。
    • cd/Mozilla-central-83bf4fd3b1fb/testing/geckodriver/src/ 并使用您喜欢的编辑器编辑 prefs.rs。最后写下:
    // Disable CSP
    ("security.csp.enable", Pref::new(false)),
    
    • 使用 cargo 或 mach 构建 geckodriver。我用cargo build

    • 加载它使用:

    webdriver.Firefox(executable_path='./mozilla-central-83bf4fd3b1fb/testing/geckodriver/target/debug/geckodriver')
    

    查找文档、浏览源代码和编辑非常痛苦,因为我不了解 Rust。这是文档:Building Docs

    【讨论】:

      猜你喜欢
      • 2011-07-13
      • 1970-01-01
      • 1970-01-01
      • 2012-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-27
      • 1970-01-01
      相关资源
      最近更新 更多