驱动下载地址:https://github.com/mozilla/geckodriver/releases/tag/v0.26.0 http://ftp.mozilla.org/pub/firefox/releases/
查看版本号:
火狐驱动提示:NotADirectoryError: [WinError 267] 目录名称无效。: ‘D:\tools\Program Files\Driver\geckodriver.exe’
from selenium import webdriver
FFpath = r'D:\tools\Program Files\Driver\geckodriver.exe'
driver = webdriver.Firefox(FFpath)
一直报错
"D:\tools\Program Files (x86)\Python3.6.4\python.exe" D:/file/PycharmProjects/untitled/产权/交易公告管理.py
Traceback (most recent call last):
File "D:/file/PycharmProjects/untitled/产权/交易公告管理.py", line 4, in <module>
from cfg01 import *
File "D:\file\PycharmProjects\untitled\cfg01.py", line 7, in <module>
driver = webdriver.Firefox(FFDriverServer)
File "D:\tools\Program Files (x86)\Python3.6.4\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 151, in __init__
firefox_profile = FirefoxProfile(firefox_profile)
File "D:\tools\Program Files (x86)\Python3.6.4\lib\site-packages\selenium\webdriver\firefox\firefox_profile.py", line 80, in __init__
ignore=shutil.ignore_patterns("parent.lock", "lock", ".parentlock"))
File "D:\tools\Program Files (x86)\Python3.6.4\lib\shutil.py", line 309, in copytree
names = os.listdir(src)
NotADirectoryError: [WinError 267] 目录名称无效。: 'D:\\tools\\Program Files\\Driver\\geckodriver.exe'
原因是WebDirver Firefox方法调用方式不对:改成如下方式:
from selenium import webdriver
# 这里要指定executeable_path参数来传参数
FFDriverServer = r'D:\tools\Program Files\Driver\geckodriver.exe'
driver = webdriver.Firefox(executable_path=FFDriverServer)