【问题标题】:firefoxprofile not working if firefoxbinary is set as webdriver.Firefox(firefox_profile=profile, firefox_binary=binary)如果 firefoxbinary 设置为 webdriver.Firefox,则 firefoxprofile 不起作用(firefox_profile=profile,firefox_binary=binary)
【发布时间】:2022-01-18 19:48:17
【问题描述】:

我注意到如果我在webdriver 中使用firefox_binaryfirefox_profile 不是working.im 得到我的标准useragent

profile = FirefoxProfile(r".\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default")
binary = FirefoxBinary(r".\Tor Browser\Browser\firefox.exe")
ua = UserAgent()
userAgent = ua.random
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", userAgent)
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary)

但如果使用driver = webdriver.Firefox(firefox_profile=profile),我会看到更新后的用户代理,但正常的 Firefox 正在使用我的标准 ip 打开。

我做错了什么? 我的操作系统在 Windows 11Python 3.9.9

我还看到,当我使用带有地址栏“未连接”的 firefox_binary 的 webdriver 时,但例如 https://api.ipify.org 的网站总是显示另一个 IP。那是问题吗? 如果我使用webdriver 而不使用firefox_binary,则在地址栏右侧什么也看不到。

【问题讨论】:

    标签: python selenium user-agent tor selenium-firefoxdriver


    【解决方案1】:

    有一个问题是您将 profile 声明为变量两次:

    profile = FirefoxProfile(r".\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default")
    
    profile = webdriver.FirefoxProfile()
    

    修改如下:

    prof = FirefoxProfile(r".\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default")
    
    profile = webdriver.prof
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多