简体   繁体   English

尝试在python3中使用硒创建浏览器时出错

[英]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. 我正在尝试在python3使用selenium来强制执行javascript ,然后使用BeautifulSoup返回/解析呈现的html Unfortunately I get stopped very quickly when trying to use selenium . 不幸的是,当我尝试使用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 . 您需要手动安装SafariDriver扩展程序,请参见此处

Basically, download the driver from here with Safari, according to your Selenium version. 基本上,根据您的Selenium版本从此处从 Safari下载驱动程序。 And click install. 然后点击安装。

After that, your python code should work. 之后,您的python代码应该可以工作了。 (again, it depends on versions... not all Safari versions are supported, especially on Windows) (同样,它取决于版本...并非所有Safari版本都受支持,尤其是在Windows上)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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