今天做爬虫的时候,在IDLE上面要使用火狐浏览器驱动器时候,反复出现下面错误:
Traceback (most recent call last):
File “<pyshell#9>”, line 1, in
driver=webdriver.Firefox(r’E:\driver\geckodriver.exe’)
File “C:\Users\lenovo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\firefox\webdriver.py”, line 151, in init
firefox_profile = FirefoxProfile(firefox_profile)
File “C:\Users\lenovo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\firefox\firefox_profile.py”, line 79, in init
shutil.copytree(self.profile_dir, newprof,
File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\shutil.py”, line 552, in copytree
with os.scandir(src) as itr:
NotADirectoryError: [WinError 267] 目录名称无效。: ‘E:\\driver\\geckodriver.exe’
火狐版本过高了,直接用webdriver去启动已经不行了,需要加上两个参数:
driverpath='E:\driver\geckodriver.exe' //驱动器的位置
driver=webdriver.Firefox(executable_path=driverpath,service_log_path=r"E:\\driver\\watchlog.log") //第一个参数为配置执行路径,第二个必须加上为产生的日志文件和位置
直接在IDLE上就可以启动火狐了