问题描述
我正在编写一个程序,该程序将在网站中搜索文章内的特定条目,我正在使用针对Python的硒网络驱动程序。
I'm writing a program that will search a website for specific entries inside of articles, I'm using selenium webdriver for Python.
尝试连接到我收到此异常的网站:
While attempting to connect to the site I get this exception:
Traceback (most
recent call last):
File "search.py", line 26, in <module>
test.search_for_keywords()
File "search.py", line 13, in search_for_keywords
browser = webdriver.Firefox()
File "C:\Python27\lib\site-packages\selenium-3.0.0b2-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 65, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium-3.0.0b2-py2.7.egg\selenium\webdriver\common\service.py", line 86, in start
self.assert_process_still_running()
File "C:\Python27\lib\site-packages\selenium-3.0.0b2-py2.7.egg\selenium\webdriver\common\service.py", line 99, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 2
这是说网络驱动程序意外退出。如何解决此问题?我正在尝试将Firefox版本48.0与python版本2.7.12连接起来
It's saying that the webdriver unexpectedly exited. How can I fix this issue? I'm trying to connect with firefox version 48.0 with python version 2.7.12
推荐答案
最新运行python硒测试Firefox浏览器(以上版本47)
木偶或 Gecko驱动程序是firefox驱动程序的未来版本。 Firefox 47+与Selenium 2.53中使用的驱动程序不兼容,Selenium 3+将使用名为 Marionette或 Gecko Driver(尚未正式发布)的新驱动程序。
"Marionette" or "Gecko Driver" is the future version of firefox driver. Firefox 47+ is not compatible with the driver used in Selenium 2.53, and Selenium 3+ will be using a new driver called "Marionette" or "Gecko Driver" (which isn't officially released yet).
先决条件:
•Mozilla firefox:版本50.0.2(以上版本47)
• Mozilla firefox : Version 50.0.2(Version 47 above)
•Selenium:3.0.2版
• Selenium : Version 3.0.2
•Geckodriver:0.11.1版
• Geckodriver : Version 0.11.1
•Python:版本2.7.3
• Python : Version 2.7.3
设置:
•Selenium: pip install –U硒
• Selenium : pip install –U selenium
•Geckodriver:从,解压缩文件并将其放在文件夹中
• Geckodriver : Download the geckodriver from https://github.com/mozilla/geckodriver/releases , unzip the file and place it in a folder
•使用geckodriver路径设置'Path'环境变量
• Set the ‘Path’ environment variable with geckodriver path
示例脚本:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
#提供Firefox二进制路径
binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe’)
caps = DesiredCapabilities.FIREFOX.copy()
#将木偶浏览器设置为True
caps['marionette'] = True
#启动Firefox实例通过指定geckodriver可执行文件路径
driver = webdriver.Firefox(firefox_binary=binary,capabilities=caps, executable_path`='D:/Installers/geckodriver-v0.11.1-win64/geckodriver')
您已完成...!
这篇关于Selenium Firefox Webdriver导致错误:服务geckodriver意外退出。状态码为:2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!