用python使用selenium 模擬firefox來抓取網頁時, 會出現提示FileNotFoundError: [WinError 2] 系統找不到指定的文件的問題,
代碼:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
運行後會出現提示
============= RESTART: D:\python\test.py =============
Traceback (most recent call last):
File "C:\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 62, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Python\Python36\lib\subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "C:\Python\Python36\lib\subprocess.py", line 957, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] 系統找不到指定的文件。
解決方法:
打開python目錄下的lib文件夾,找到subprocess.py
1、搜索class Popen(object):
2、將__init__中的shell=False修改爲shell=True
重新運行就能正常執行了。