从selenium打开浏览器时出错

时间:2017-07-20 01:30:15

标签: python-3.x selenium webdriver selenium-chromedriver

我的剧本

from selenium import webdriver
o = webdriver.Firefox()

我遇到了这个问题

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 142, in __init__
    self.service.start()
File "/usr/local/lib/python3.5/dist-packages/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 676, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1283, in _execute_child
    raise child_exception_type(errno_num, err_msg)
OSError: [Errno 8] Exec format error

我搜索了它,我发现了这个 OSError: [Errno 8] Exec format error selenium

我得到了chromedriver并把它放在&#39; / usr / local / bin /&#39; 像所谓的, 它没有帮助 并且也和geckodriver做了同样的事情 Trouble setting up selenium with python3(linux)

没有什么工作相同的错误

我试试这个镜头

#!usr/bin/python
#!/usr/bin/env bash
from selenium import webdriver 
web = webdriver.Firefox(executable_path="/usr/local/bin/chromedriver")

它给了我那个错误:

Traceback (most recent call last):
  File "/root/Desktop/test.py", line 5, in <module>
    web = webdriver.Firefox(executable_path="/usr/local/bin/chromedriver")
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 142, in __init__
    self.service.start()
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 96, in start
    self.assert_process_still_running()
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running
    % (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/local/bin/chromedriver unexpectedly exited. Status code was: 1

注意: 操作系统是kali linux SMP Debian 4.9.18-1kali1版本, firefox和selenium是最新的

2 个答案:

答案 0 :(得分:0)

驱动程序应该更新一个&amp;你试过webdriver.Firefox(driver_path)吗?

答案 1 :(得分:0)

卸载webdriver依赖项的实例并安装与您的操作系统和浏览器版本相对应的正确实例。当您提供chrome路径时,它应以chrome.exe而不是chrome结束。