最近我一直在尝试重新建立Selenium环境。脚本正常执行,使用不同的Web驱动程序等等,一切都应该正常运行。
然而,每个驱动程序的初始启动时间需要2-5分钟之间。这使得开发和调试我的脚本非常麻烦。
我使用Python 3.6与PyCharm以及通过pip安装的Selenium。相同的问题也存在于Python 2.7上。
到目前为止,我尝试了以下几种方法(但没有成功):
- 重新安装Python
- 重新安装Selenium
- 通过PyCharm和终端运行脚本
- 用早期或更高版本的Web驱动程序替换
- 禁用Web驱动程序的代理和JavaScript
以下是我正在运行的内容。这个简单的脚本需要最多5分钟才能运行,但是会正确地工作,并且没有任何警告或错误。
from selenium import webdriver
import time
print(time.localtime())
browser = webdriver.Firefox()
browser.get('http://seleniumhq.org/')
print(time.localtime())
编辑: 以上代码的单次运行会产生以下geckodriver.log
1528112695159 geckodriver INFO geckodriver 0.19.1
1528112695168 geckodriver INFO Listening on 127.0.0.1:3148
1528112747876 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\victorsk\\AppData\\Local\\Temp\\rust_mozprofile.ULuflXGoq9rE"
Unable to read VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\victorsk\AppData\Local\openvr\openvrpaths.vrpath
1528112791808 Marionette INFO Listening on port 3158
1528112792599 Marionette WARN TLS certificate errors will be ignored for this session
[Parent 36664, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Parent 36664, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 22672, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 22672, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/sr[Parent 36664, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 25068, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 25068, C*** UTM:SVC TimerManager:registerTimer called after profile-before-change notification. Ignoring timer registration for id: telemetry_modules_ping