gpt4 book ai didi

python - Selenium:FirefoxProfile 失败,未找到异常

转载 作者:行者123 更新时间:2023-11-28 17:52:49 26 4
gpt4 key购买 nike

我有以下代码,尽管我设置了 profile_directory Firefox webdriver 仍然尝试将设置存储在 /tmp 文件夹中

profile = FirefoxProfile(profile_directory = '/home/sultan/profiles')
profile.set_preference('network.proxy.http', scheme);
profile.set_preference('network.proxy.http_port', self.proxy.get('port'));

异常代码:

File "/home/sultan/Repository/Django/monitor/app/utils.py", line 79, in start
request.perform(scan = scan, schedule = schedule)
File "/home/sultan/Repository/Django/monitor/app/request.py", line 230, in perform
profile1 = FirefoxProfile(profile_directory = '/home/sultan/profiles')
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_profile.py", line 97, in __init__
self._read_existing_userjs()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_profile.py", line 178, in _read_existing_userjs
f = open(os.path.join(self.profile_dir, 'user.js'), "r")
IOError: [Errno 2] No such file or directory: '/tmp/webdriver-py-profilecopy/user.js'

我做错了什么,或者我需要为 selenium 添加特定的配置设置吗?

最佳答案

我也有同样的问题。由于 FF5 在配置文件中没有“user.js” -> 我们不必阅读它。

打开 selenium/webdriver/firefox/firefox_profile.py 并在 def _read_existing_userjs(self) 之后添加 try except,如下所示:

def _read_existing_userjs(self):
try:
f = open(os.path.join(self.profile_dir, 'user.js'), "r")
except IOError, e:
print "We didn't find user.js in your profile, but that is ok"
return

tmp_usr = f.readlines()
f.close()
for usr in tmp_usr:
matches = re.search('user_pref\("(.*)",\s(.*)\)', usr)
self.default_preferences[matches.group(1)] = matches.group(2)

关于python - Selenium:FirefoxProfile 失败,未找到异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6652819/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com