Python Selenium 浏览器 火狐

标签 python selenium selenium-webdriver

想要一些帮助来解释为什么这不起作用

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://www.google.com')

错误:

Traceback (most recent call last):
  File "C:/Users/cycli/Desktop/test.py", line 2, in <module>
    browser = webdriver.Firefox()
  File "D:\Python\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
    self.service.start()
  File "D:\Python\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
    self.assert_process_still_running()
  File "D:\Python\lib\site-packages\selenium\webdriver\common\service.py", line 111, in assert_process_still_running
    % (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 3221225595

最佳答案

从下面的链接下载适用于 Firefox 的 geckodriver,

https://github.com/mozilla/geckodriver/releases

geckodriver 必须位于代码路径中,或者必须指定它的路径。

from selenium.webdriver.firefox.options import Options
#Setting up FireFox Driver Options
driver_options = Options()
profile = webdriver.FirefoxProfile()
#driver_options.add_argument("--headless")
driver = webdriver.Firefox(
                firefox_profile=profile, 
                options=driver_options,
                executable_path="geckodriver.exe")

关于Python Selenium 浏览器 火狐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58225388/

相关文章:

java - 通过 Selenium 直接按 "F12"键

javascript - Selenium xpath 问题

selenium-webdriver - 使用 Mocha 的 Selenium Java Script Webdriver - 如果测试失败,请截取屏幕截图

python - 值错误 : Missing staticfiles manifest entry for 'favicon.ico'

Python:唯一标识模块中的函数

css - 以下 html 片段需要 xpath 或 css

java - fluidwait<webdriver> 类型中的 withtimeout(duration) 方法不适用于参数 (int, timeunit)

python - 4.16 实验室: Warm up: Drawing a right triangle

python - 日期范围内的 xlsxwriter

java - 使用 selenium 查找按钮 id