无法使用Chrome和Firefox在Linux上运行Selenium + Python脚本

问题描述 投票:3回答:3

我无法在Linux Mint 18.1 Serena上使用Chrome和Firefox运行/执行python(3.5)+ selenium(3.4.0)脚本。

细节:

当我尝试在Chrome或Firefox浏览器的脚本下运行时,我遇到了问题,它在Windows机器上运行得非常好,但在Linux Mint上给出了一些奇怪的问题。

铬:-

import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://www.google.com/xhtml');
driver.close()

结果:-

Traceback (most recent call last):
File "sample1.py", line 6, in <module>
driver.get('http://www.google.com/xhtml');
File "/usr/local/lib/python3.5/dist-packages/selenium-3.4.0-py3.5.egg /selenium/webdriver/remote/webdriver.py", line 261, in get
self.execute(Command.GET, {'url': url})
File "/usr/local/lib/python3.5/dist-packages/selenium-3.4.0-py3.5.egg/selenium/webdriver/remote/webdriver.py", line 247, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python3.5/dist-packages/selenium-3.4.0-py3.5.egg/selenium/webdriver/remote/remote_connection.py", line 464, in execute
return self._request(command_info[0], url, body=data)
File "/usr/local/lib/python3.5/dist-packages/selenium-3.4.0-py3.5.egg/selenium/webdriver/remote/remote_connection.py", line 488, in _request
resp = self._conn.getresponse()
File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse
response.begin()
File "/usr/lib/python3.5/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.5/http/client.py", line 266, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

FireFox: -

import time
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.google.com/xhtml');
driver.close()

结果:-

Traceback (most recent call last):
File "sample1.py", line 4, in <module>
driver = webdriver.Firefox()
File "/usr/local/lib/python3.5/dist-packages/selenium-3.4.0-py3.5.egg/selenium/webdriver/firefox/webdriver.py", line 142, in __init__
self.service.start()
File "/usr/local/lib/python3.5/dist-packages/selenium-3.4.0-py3.5.egg/selenium/webdriver/common/service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error
python google-chrome selenium selenium-chromedriver mint
3个回答
3
投票

我通过更改geckodriver的权限并在/ usr / local / bin下移动geckodriver来解决问题

chmod +x geckodriver
cp geckodriver /usr/local/bin/

我认为它对chromedriver也会有效。感谢所有帮助人员


0
投票

好的,所以看看周围,这似乎是关于你至少使用geckodriver的二进制文件的抱怨。在这里看到OSError: [Errno 8] Exec format error selenium

您应该检查为其设置路径的geckodriver / chromedrive,并确保您使用的二进制文件不适用于Windows版本(我怀疑它是因为它适用于Windows而不适用于linux mint的原因 - 假设您'共享机器)

我希望能帮助你。 :)(我必须承认,但我不太清楚为什么两个浏览器的错误完全不同)


0
投票

问题可能是Pycharm。如果我从终端运行,它工作正常。可能是Pycharm的权限问题。

© www.soinside.com 2019 - 2024. All rights reserved.