简体   繁体   English

从 python 关闭 chrome,终止进程

[英]Close chrome from python, kill the process

I want in the program below to close the process I open in the beginning, ¿How could I kill it in order to close the chrome browser window?我想在下面的程序中关闭我一开始打开的进程,¿我怎样才能杀死它以关闭 chrome 浏览器 window? Here's the code:这是代码:

from selenium import webdriver
import subprocess

subprocess.Popen('"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" --remote-debugging-port=9222 --incognito', shell=True)
driver_path = 'chromedriver.exe'
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(driver_path, options=options)
driver.get('myurl')
#Here I would like to kill the process I opened above, close chrome and quit selenium

It should be achievable via .kill() :它应该可以通过.kill()实现:

proc = subprocess.Popen(...)
# Do stuff...
proc.kill()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM