获取由 selenium 启动的浏览器的 PID [英] Get PID of Browser launched by selenium
本文介绍了获取由 selenium 启动的浏览器的 PID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获取 selenium 启动的浏览器的 PID.有没有办法完成它?
I would like to get the PID of the browser launched by selenium. Is there any way to get it done?
推荐答案
使用 Python API,非常简单:
Using the Python API, it's pretty simple:
from selenium import webdriver
browser = webdriver.Firefox()
print browser.binary.process.pid
# browser.binary.process is a Popen object...
如果您使用 Chrome,它会稍微复杂一些,您可以通过 chromedriver 进程:
If you're using Chrome, it's a little more complex, you go via a chromedriver process:
c = webdriver.Chrome()
c.service.process # is a Popen instance for the chromedriver process
import psutil
p = psutil.Process(c.service.process.pid)
print p.get_children(recursive=True)
这篇关于获取由 selenium 启动的浏览器的 PID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文