I'm writing a bunch of programs using python selenium. In order to scrape content from different websites, I need to download chromedriver.exe that is compatible with my current version of chrome. However, chrome is constantly being updated, so I want to write a program that will first check if chrome and chromedriver versions are compatible before running my programs. So, I need a way to get my current chrome version without using chromewebdriver or actually opening up a browser. Any suggestions?
Asked
Active
Viewed 1,040 times
2 Answers
0
For windows you could try with the CMD reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome" as follow:
import os
stream = os.popen('reg query "HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Google Chrome"')
output = stream.read()
print(output)
To extract the google_version from the output you could try the following:
import os
def extract_version(output):
try:
google_version = ''
for letter in output[output.rindex('DisplayVersion REG_SZ') + 24:]:
if letter != '\n':
google_version += letter
else:
break
return(google_version.strip())
except TypeError:
return
stream = os.popen('reg query "HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Google Chrome"')
output = stream.read()
google_version = extract_version(output)
print(google_version)
Mateo Lara
- 740
- 1
- 10
- 26
0
If you are working on Linux:
Try this in terminal(If you want to get the result in python script, you need to use subprocess.popen()):
google-chrome --version
You may need to use which google-chrome to know whether you have install it.Hope it would help.
Kevin Mayo
- 1,019
- 5
- 18
-
process = subprocess.Popen(["chromium-browser", "-version"], stdout=PIPE) output = process.communicate()[0] works for me. – modernxart Oct 10 '21 at 04:42