在python 3中用硒启动chromedriver时, 加载时一切似乎至少可以进行一秒钟, 但随后会弹出此错误消息:
Traceback (most recent call last):
File "C:\...\Selenium\UsingChrome.py3", line 15, in <module>
driver = webdriver.Chrome(executable_path="chromedriverwin32.exe")
File "c:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "c:\Users\...AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
self.assert_process_still_running()
File "c:\Users\...\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service chromedriverwin32.exe unexpectedly exited. Status code was: 3221225477
我当前的代码是:
from selenium import webdriver
import time, os
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.binary_location = 'chromedriver.exe'
driver = webdriver.Chrome(chrome_options=options)
driver.get('https://python.org')
...我尝试为chromedriver位置使用绝对路径,但这仍然无济于事(chromedriver.exe文件与脚本位于同一目录中)
我正在Windows 10笔记本电脑上的python 3.6.5上运行它
我已经在网上搜索了大约3个小时,但是没有遇到与我得到的相同的错误状态代码。
答案 0 :(得分:0)
好的,这真的很奇怪。 Chromedriver selenium在交互式外壳中启动时效果很好,但在执行脚本时效果不佳。 在我的机器上,我设置了一些批处理文件,这些批处理文件在执行python脚本时运行(运行诸如Ansicon.exe之类的命令,以便在cmd中进行彩色显示),并在使用命令'python3 script.py运行python脚本后执行'它完美地工作... 所以我不确定为什么以前没有,但是无论如何,现在已经解决了。
我的代码现在是:
#some fake code here
for pos, file_name in np.arange(0, 11000, 1000):
data = read(file_name)
modelpath = . . .
checkpoint = ModelCheckpoint(modelpath, period=15, . . .)
callbacks_list = [checkpoint]
initial_epoch=0
file_list = os.listdir(main_path + 'modles/')
if len(file_list) > 0:
epoch_list = get_file_list(main_path + 'modles/')
epoch_last = epoch_list[-1]
model.load_weights(main_path + 'modles/' + epoch_last)
print("checkpoint_loaded: ", epoch_last)
if epoch_last.split('-')[2] == '015' and epoch_last.split('-')[1] == file_name:
initial_epoch = 15
if epoch_last.split('-')[2] == '030' and epoch_last.split('-')[1] == file_name:
initial_epoch = 30
print('Begin from epoch: ', str(initial_epoch))
model.fit([data],
epochs=30,
batch_size=10,
validation_split=0.1,
callbacks=callbacks_list,
initial_epoch=initial_epoch
)
并且要启动的批处理文件为一行:
from selenium import webdriver
browser = webdriver.Chrome()
while 1: pass # wait forever just to let chromedriver be interactive