python selenium3.0 解決:提示FileNotFoundError: [WinError 2] 系統找不到指定的文件問題

用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

重新運行就能正常執行了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章