【问题标题】:AttributeError: 'FirefoxProfile' object has no attribute 'update' error usingFirefoxProfile through Selenium and Python [closed]AttributeError:'FirefoxProfile'对象没有属性'update'错误使用FirefoxProfile通过Selenium和Python [关闭]
【发布时间】:2019-11-28 11:00:20
【问题描述】:

大家好,我的代码有问题。

from selenium import webdriver
import time

profile = webdriver.FirefoxProfile()
profile.set_preference('network.proxy_type',1)
profile.set_preference('network.proxy.http',"91.xx.xxx.xx")
profile.set_preference('network.proxy.http_port',xxxx)
# profile.update_preference()  ---> this code letter giving the error.
driver = webdriver.Firefox(firefox_profile=profile)
driver.get('http://whatismyipaddress.com')
time.sleep(3)
driver.close()

这是我遇到的错误:

AttributeError: 'FirefoxProfile' object has no attribute 'update'

我无法弄清楚我只想保存配置文件设置以供使用的问题。

【问题讨论】:

  • update_preferences(),与s

标签: python selenium selenium-webdriver firefox firefox-profile


【解决方案1】:

我认为你需要改变这一点

profile.update_preference()

有了这个:

profile.update_preferences()

【讨论】:

    【解决方案2】:

    update_preferences()

    update_preferences() 使用所需 FirefoxProfilefrozen 首选项更新 default_preferences,该首选项定义为:

    def update_preferences(self):
        for key, value in FirefoxProfile.DEFAULT_PREFERENCES['frozen'].items():
            self.default_preferences[key] = value
        self._write_user_prefs(self.default_preferences)
    

    但是,你很接近。您需要用 update_preferences() 替换 update_preference(),即在您需要替换的代码中有效:

    profile.update_preference()
    

    profile.update_preferences()
    

    参考

    您可以在以下位置找到相关讨论:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 2022-01-17
      • 2018-12-20
      • 2016-07-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多