AttributeError: 'FirefoxProfile' object has no attribute 'update' error usingFirefoxProfile through Selenium and Python
AttributeError: 'FirefoxProfile' object has no attribute 'update' error usingFirefoxProfile through Selenium and Python
大家好,我的代码有问题。
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'
我想不通我只是想保存配置文件设置以供使用。
我认为你需要改变这个
profile.update_preference()
有了这个:
profile.update_preferences()
update_preferences()
update_preferences() 使用所需 FirefoxProfile 的 frozen 首选项更新 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_preference()
替换为 update_preferences()
即有效地在您的代码中您需要替换:
profile.update_preference()
和
profile.update_preferences()
参考资料
您可以在以下位置找到相关讨论:
大家好,我的代码有问题。
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'
我想不通我只是想保存配置文件设置以供使用。
我认为你需要改变这个
profile.update_preference()
有了这个:
profile.update_preferences()
update_preferences()
update_preferences() 使用所需 FirefoxProfile 的 frozen 首选项更新 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_preference()
替换为 update_preferences()
即有效地在您的代码中您需要替换:
profile.update_preference()
和
profile.update_preferences()
参考资料
您可以在以下位置找到相关讨论: