为什么 Selenium 不能加载 firefox 配置文件?
Why wouldn't Selenium be able to load a firefox profile?
以下代码:
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
import os.path
import os
FIREFOX_PATH = os.path.join("C:",
"FirefoxPortable", "FirefoxPortable.exe")
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary(FIREFOX_PATH)
driver = webdriver.Firefox(firefox_binary=binary)
# go to the google home page
driver.get("http://www.google.com")
投诉无法加载配置文件失败:
$ python test_selenium.py
Traceback (most recent call last):
File "test_selenium.py", line 17, in <module>
driver = webdriver.Firefox(firefox_profile=profile,firefox_binary=binary)
File "/usr/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
File "/usr/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 66, in launch_browser
self._wait_until_connectable()
File "/usr/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 105, in _wait_until_connectable
raise WebDriverException("Can't load the profile. Profile "
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.
有什么想法吗?
我承认我一点也不关心配置文件(并且对它们是什么只有最模糊的感觉)- 我只想要加载一个基本的浏览器,这样我就可以自动执行一些网络抓取。
非常感谢!
/YGA
根据 this 问题,指定如下路径有效。这会在 D:/
.
中搜索 FirefoxPortable
文件夹
FIREFOX_PATH = os.path.join("D:/", "FirefoxPortable", "FirefoxPortable.exe")
另外,下面的代码工作正常。我删除了 import os
行,因为它是多余的。
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
import os.path
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
FIREFOX_PATH = os.path.join("D:/", "FirefoxPortable", "FirefoxPortable.exe")
binary = FirefoxBinary(FIREFOX_PATH)
driver = webdriver.Firefox(firefox_binary=binary)
# go to the google home page
driver.get("http://www.google.com")
driver.quit()
以下代码:
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
import os.path
import os
FIREFOX_PATH = os.path.join("C:",
"FirefoxPortable", "FirefoxPortable.exe")
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary(FIREFOX_PATH)
driver = webdriver.Firefox(firefox_binary=binary)
# go to the google home page
driver.get("http://www.google.com")
投诉无法加载配置文件失败:
$ python test_selenium.py
Traceback (most recent call last):
File "test_selenium.py", line 17, in <module>
driver = webdriver.Firefox(firefox_profile=profile,firefox_binary=binary)
File "/usr/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
File "/usr/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 66, in launch_browser
self._wait_until_connectable()
File "/usr/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 105, in _wait_until_connectable
raise WebDriverException("Can't load the profile. Profile "
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.
有什么想法吗?
我承认我一点也不关心配置文件(并且对它们是什么只有最模糊的感觉)- 我只想要加载一个基本的浏览器,这样我就可以自动执行一些网络抓取。
非常感谢! /YGA
根据 this 问题,指定如下路径有效。这会在 D:/
.
FirefoxPortable
文件夹
FIREFOX_PATH = os.path.join("D:/", "FirefoxPortable", "FirefoxPortable.exe")
另外,下面的代码工作正常。我删除了 import os
行,因为它是多余的。
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
import os.path
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
FIREFOX_PATH = os.path.join("D:/", "FirefoxPortable", "FirefoxPortable.exe")
binary = FirefoxBinary(FIREFOX_PATH)
driver = webdriver.Firefox(firefox_binary=binary)
# go to the google home page
driver.get("http://www.google.com")
driver.quit()