如何解决如何识别正在使用的 geckodriver.exe?
我的电脑上有多个 geckodriver.exe 的副本,它们可能是不同的版本,我从我的电脑运行我的 python 脚本,但不知道实际使用的是哪个。我没有在脚本中明确指定 geckodriver.exe: ...
path2ff = os.environ.get('LOCALAPPDATA') + r'\Mozilla Firefox\firefox.exe'
binary = FirefoxBinary(path2ff)
dr = webdriver.Firefox(firefox_binary=binary,firefox_profile=profile)
现在我需要将脚本编译成可执行文件分发给其他用户,不知道我需要发送哪个geckodriver.exe。
感谢任何建议。
亨氏
解决方法
概括地说,我会使用 Python 的 WMI(Windows 管理规范)库列出您机器上运行的所有进程,找到 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}")
在该 process
循环的 for
对象中读取 CommandLine
变量,它将为您提供路径。
有关 WMI 文档,请参阅 https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-process。
样本输出:
pid Process name CommandLine
14404 RuntimeBroker.exe C:\Windows\System32\RuntimeBroker.exe -Embedding
14616 nvsphelper64.exe None
14636 NVIDIA Share.exe "C:\Program Files\NVIDIA Corporation\NVIDIA GeForce Experience\NVIDIA Share.exe"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。