Python Selenium -> 检查是否安装了 Firefox 32/64 位或 Chrome 32/64 位?
Python Selenium -> Check whether Firefox 32/64bit or Chrome 32/64bit installed?
我使用 32 位 geckodriver.exe 编写了一个 python 脚本。
我将此脚本与 geckodriver 一起打包为 Pyinstalled .exe 文件。
我发现,当有人使用 Firefox 64 位时,此 .exe 不会 运行。
显然,当有人根本不使用 Firefox 时,它也不起作用,而是 Chrome。
所以理论上,是的,我可以将 2 个 geckodriver 版本 (32/64) 和 2 个 chromedriver 版本 (32/64) 打包到 .exe 中,但是我如何找出哪个浏览器和哪个版本 (32/64)安装在用户的系统上?
它只是 windows 系统...那么有没有办法通过读取用户注册表来解决问题?
任何想法表示赞赏。
谢谢!
我想你可以像这样用注册表来做:
from winreg import HKEY_LOCAL_MACHINE
import winreg
try:
winreg.OpenKey(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe', 0, KEY_ALL_ACCESS).Close()
except FileNotFoundError:
print('Chrome not installed')
Firefox 也一样
下面是一个在函数中使用它的好方法:
import os
import win32file
from winreg import *
import winreg
CHROME_KEY = 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
def is_chrome_installed():
try:
key = winreg.OpenKey(HKEY_LOCAL_MACHINE, CHROME_KEY, 0, KEY_ALL_ACCESS)
path_dir = QueryValueEx(key, "PATH")[0]
file_arc = win32file.GetBinaryType(os.path.join(path_dir, 'chrome.exe'))
if file_arc == 0:
print('its a 32bit')
elif file_arc == 6:
print('its a 64bit')
return True
except FileNotFoundError:
print('Chrome not installed')
return False
请注意,您需要成为 运行 管理员才能正常工作
我使用 32 位 geckodriver.exe 编写了一个 python 脚本。 我将此脚本与 geckodriver 一起打包为 Pyinstalled .exe 文件。
我发现,当有人使用 Firefox 64 位时,此 .exe 不会 运行。 显然,当有人根本不使用 Firefox 时,它也不起作用,而是 Chrome。
所以理论上,是的,我可以将 2 个 geckodriver 版本 (32/64) 和 2 个 chromedriver 版本 (32/64) 打包到 .exe 中,但是我如何找出哪个浏览器和哪个版本 (32/64)安装在用户的系统上?
它只是 windows 系统...那么有没有办法通过读取用户注册表来解决问题? 任何想法表示赞赏。
谢谢!
我想你可以像这样用注册表来做:
from winreg import HKEY_LOCAL_MACHINE
import winreg
try:
winreg.OpenKey(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe', 0, KEY_ALL_ACCESS).Close()
except FileNotFoundError:
print('Chrome not installed')
Firefox 也一样
下面是一个在函数中使用它的好方法:
import os
import win32file
from winreg import *
import winreg
CHROME_KEY = 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'
def is_chrome_installed():
try:
key = winreg.OpenKey(HKEY_LOCAL_MACHINE, CHROME_KEY, 0, KEY_ALL_ACCESS)
path_dir = QueryValueEx(key, "PATH")[0]
file_arc = win32file.GetBinaryType(os.path.join(path_dir, 'chrome.exe'))
if file_arc == 0:
print('its a 32bit')
elif file_arc == 6:
print('its a 64bit')
return True
except FileNotFoundError:
print('Chrome not installed')
return False
请注意,您需要成为 运行 管理员才能正常工作