Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
646 views
in Technique[技术] by (71.8m points)

python - OSError: [Errno 8] Exec format error selenium

Trying to learn how to use selenium, I managed to overcome first error which involved chrome driver not being in the path name but it has thrown up another error.

  from selenium import webdriver
    from selenium.webdriver.common.keys import Keys


    driver = webdriver.Chrome('/Users/williamneal/Scratch/Titanic/chromedriver')
    driver.get("http://www.bbc.com")

The error: Traceback (most recent call last):

  File "<ipython-input-1-84256e62b8db>", line 5, in <module>
    driver = webdriver.Chrome('/Users/williamneal/Scratch/Titanic/chromedriver')

  File "/Users/williamneal/anaconda/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
    self.service.start()

  File "/Users/williamneal/anaconda/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 64, in start
    stdout=self.log_file, stderr=self.log_file)

  File "/Users/williamneal/anaconda/lib/python3.5/subprocess.py", line 950, in __init__
    restore_signals, start_new_session)

  File "/Users/williamneal/anaconda/lib/python3.5/subprocess.py", line 1544, in _execute_child
    raise child_exception_type(errno_num, err_msg)

OSError: [Errno 8] Exec format error

There is a potential solution here, which involves installing Chrome Drivers via Home Brew but that option is not available to me.

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Looks like this is complaining about the format of chromedriver binary. It might be because of platform and chromedriver format mismatch. For example windows requires chromedriver.exe while there are different formats for linux and mac.

If you don't want to install through package manager, just download chromedriver from https://sites.google.com/a/chromium.org/chromedriver/downloads

Note : Choose file as per your os

Then place it anywhere on the os and pass that path as an argument. You can also set webdriver.chrome.driver environment variable if you don't want to pass the location every time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...