gpt4 book ai didi

python - 无法使用 Chrome 和 firefox 在 linux mint 上运行 Selenium + Python 脚本

转载 作者:太空宇宙 更新时间:2023-11-03 15:55:20 24 4
gpt4 key购买 nike

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

详细信息:

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

Chrome :-

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

火狐:-

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

最佳答案

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

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

我认为它对 chromedriver 也同样有效感谢大家的帮助

关于python - 无法使用 Chrome 和 firefox 在 linux mint 上运行 Selenium + Python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43665289/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com