我遇到了与 FireFox 二进制文件相关的硒错误。
我使用反斜杠将 C:/Users/Mack/AppData/Local/Programs/Python/ 添加到 PATH 并重新启动。我在这里下载了我认为正确的文件https://github.com/mozilla/geckodriver/releases 我将该文件放在连接到 PATH 的目录中。
为了解决这个问题:我尝试使用两个反斜杠
binary = FirefoxBinary("C:\\Users\Mack\AppData\Local\Programs\Python\Python38-32\geckodriver-v0.27.0-win64\geckodriver.exe")
Run Code Online (Sandbox Code Playgroud)
这会引发相同的错误
我尝试使用一个反斜杠
binary = FirefoxBinary("C:\Users\Mack\AppData\Local\Programs\Python\Python38-32\geckodriver-v0.27.0-win64\geckodriver.exe")
Run Code Online (Sandbox Code Playgroud)
这会抛出:
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Traceback (most recent call last):
File "C:\Users\Mack\Desktop\hacker-stories\Trends.py", line 32, in <module>
browser = webdriver.Firefox(**firefox_binary=binary**)
File "C:\Users\Mack\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "C:\Users\Mack\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\Mack\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Mack\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, …Run Code Online (Sandbox Code Playgroud) from selenium import webdriver;
browser= webdriver.Firefox();
browser.get('http://www.seleniumhq.org');
Run Code Online (Sandbox Code Playgroud)
当我尝试运行此代码时,它给了我一个error message:
Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line.
Run Code Online (Sandbox Code Playgroud)
任何想法 - 高度赞赏!
我经常更新Firefox和Chrome浏览器,当前版本54.0.1 32位所以要使用哪个版本的Geckodriver.我试过两个版本Geckodriver-v0.18.0 and geckodriver-v0.16.1
为了将来参考,我在哪里可以找到支持的firefox浏览器列表以及各自的geckodriver版本
注意:启动浏览器中没有任何代码更改
以前的代码是使用geckodriver-v0.16.1为较旧的firefox版本现在在更新firefox 54.0.1和Geckodriver-v0.18.0后获得异常:
org.openqa.selenium.firefox.NotConnectedException:45000 ms后无法在端口7055上连接到主机127.0.0.1.Firefox控制台输出:oundUpdates":1,"bootstrap":false,"skinnable":false,"size":3242616,"sourceURI":null,"releaseNotesURI":null,"softDisabled":false,"foreignInstall":true "hasBinaryComponents":假 "strictCompatibility":假, "区域设置":[], "targetApplications":[{ "ID": "{ec8030f7-C20A-464f-9b0e-13a3a9e97384}", "MINVERSION":"1.5 ", "MAXVERSION": "9.9"}], "targetPlatforms":[], "multiprocessCompatible":假 "signedState":0, "看到":真 "依赖性":[], "hasEmbeddedWebExtension":假, "mpcOptedOut":假的, "userPermissions":空}
firefox selenium selenium-firefoxdriver selenium-webdriver geckodriver