如何识别哪个geckodriver.exe正在使用?



我有多个副本geckodriver.ex在我的电脑上,它们可能是不同的版本,我从我的电脑上运行我的python脚本,不知道实际使用的是哪个。我没有在脚本中明确指定geckodriver.exe:…

path2ff = os.environ.get('LOCALAPPDATA') + r'Mozilla Firefoxfirefox.exe'
binary = FirefoxBinary(path2ff)
dr = webdriver.Firefox(firefox_binary=binary, firefox_profile=profile)

现在我需要将脚本编译成可执行文件以分发给其他用户,并且不知道哪个geckodriver.exe我需要发送。

欢迎提出任何建议。

亨氏的

在高层次上,我会使用Python的WMI (Windows Management Instrumentation)库列出在您的机器上运行的所有进程,找到geckodriver.exe,然后获得它在您的系统中的位置。

获取进程列表:

import wmi
# Initializing the wmi constructor
f = wmi.WMI()

# Printing the header for the later columns
print("pid   Process name")

# Iterating through all the running processes 
for process in f.Win32_Process():

# Displaying the P_ID and P_Name of the process
print(f"{process.ProcessId:<10} {process.Name} {process.CommandLine}") 

for循环的process对象中读取CommandLine变量,它将给出路径。

参见https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-process获取WMI文档。

样本输出:

pid     Process name   CommandLine
14404      RuntimeBroker.exe C:WindowsSystem32RuntimeBroker.exe -Embedding
14616      nvsphelper64.exe None
14636      NVIDIA Share.exe "C:Program FilesNVIDIA CorporationNVIDIA GeForce ExperienceNVIDIA Share.exe"

最新更新