出错信息如下:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1540, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/dawei/Desktop/Python3/selenium_learning/tmp.py", line 5, in <module>
wd = webdriver.Firefox()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x1018dac88>>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 163, in __del__
self.stop()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
DaWei:~ dawei$ python3 /Users/dawei/Desktop/Python3/selenium_learning/tmp.py
'NoneType' object has no attribute 'path'
解决办法:请先下载geckodriver,下载好双击文件解压后会得到一个geckodriver
文件,将此文件移动到/usr/local/bin/
目录下即可。
<br />
NOTE:使用终端解压.tar.gz文件:
tar zxvf 文件路径
例如:tar zxvf ~/Downloads/geckodriver-v0.11.1-macos.tar.gz
注:不会解压到压缩文件相同目录下,会解压到终端中cd到的目录
NOTE:使用终端移动文件:
mv 文件路径 要移动到的文件夹路径
例如:sudo mv ~/Downloads/geckodriver /usr/local/bin/