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

时间:2016-11-21 09:32:31

标签: python-3.x selenium

我尝试在selenium中使用python3强制执行javascript,然后使用html返回/解析呈现的BeautifulSoup。不幸的是,在尝试使用selenium时,我很快就停止了。我这样做:

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

然后得到以下错误:

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

你知道我做错了什么吗?

1 个答案:

答案 0 :(得分:0)

您需要手动安装SafariDriver扩展程序,请参阅here

基本上,根据您的Selenium版本,使用Safari下载驱动程序from here。然后点击安装。

之后,你的python代码应该工作。 (同样,它取决于版本......并非所有Safari版本都受支持,特别是在Windows上)