简体   繁体   中英

Error trying to create a browser with selenium in python3

I am trying to use selenium in python3 to force the execution of a javascript and get back / parse the rendered html with BeautifulSoup afterwards. Unfortunately I get stopped very quickly when trying to use selenium . I do :

>>> import platform
>>> from selenium import webdriver
>>> browser = webdriver.Safari()

But then get the following error :

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    browser = webdriver.Safari()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/safari/webdriver.py", line 48, in __init__
self.service.start()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 86, in start
    self.assert_process_still_running()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 99, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/safaridriver unexpectedly exited. Status code was: 1

Do you have any clue what I do wrong?

You need to install the SafariDriver extension manually, see here .

Basically, download the driver from here with Safari, according to your Selenium version. And click install.

After that, your python code should work. (again, it depends on versions... not all Safari versions are supported, especially on Windows)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM