获取selenium启动的浏览器的PID

2024-04-19

我想获取selenium启动的浏览器的PID。有什么办法可以完成吗?


使用 Python API,非常简单:

from selenium import webdriver
browser = webdriver.Firefox()
print browser.binary.process.pid
# browser.binary.process is a Popen object...

如果您使用 Chrome,则稍微复杂一些,您可以通过 chromedriver 流程​​:

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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

获取selenium启动的浏览器的PID 的相关文章

随机推荐