我尝试过这些解决方案中的每一个都无济于事,试图实现this thread中讨论的相同内容。然而,控制台窗口仍然存在。
#kill console through .system
import os, sys
#webbrowsing modules
from selenium import webdriver
#function to launch browser in chrome
def launch_chrome(page):
browser = webdriver.Chrome(r'C:\Users\cj9250\AppData\Local\Continuum\anaconda3\chromedriver.exe')
browser.get(page)
return browser
url = "https://www.google.com/"
browser = launch_chrome(url)
#prints 'SUCCESS: The process "chromedriver.exe" with PID 9872 has been terminated.'
#in the terminal and leaves it open
os.system('taskkill /F /im chromedriver.exe')
quit()
#never gets to this print command
print('it quit')
#closes the browser as well
browser.service.stop()
sys.exit
print('it exit')
我应该注意,我正在使用win + r调用的批处理文件运行我的程序,类似于Automate the Boring Stuff中描述的方式。我也在通过Anaconda运行Python。