There's the requests and urllib page that can access http(s) protocol pages in Python, e.g.
import requests
requests.get('stackoverflow.com')
but when it comes to chrome:// pages, e.g. chrome://settings/help, the url libraries won't work and this:
import requests
requests.get('chrome://settings/help')
throws the error:
InvalidSchema: No connection adapters were found for 'chrome://settings/help'
I guess there's no way for requests or urllib to determine which chrome to use and where's the binary executable file for the browser. So the adapter can't be easily coded.
The goal here is to pythonically obtain the string Version 111.0.5563.146 (Official Build) (x86_64) from the chrome://settings/help page of the default chrome browser on the machine, e.g. it looks like this:

Technically, it is possible to get to the page through selenium e.g.
from selenium import webdriver
driver = webdriver.Chrome("./lib/chromedriver_111.0.5563.64")
driver.get('chrome://settings/help')
But even if we can get the selenium driver to get to the chrome://settings/help, the .page_source is information for Version ... is missing.
Also, other than the chrome version, the access to chrome:// pages would be used to retrieve other information, e.g. https://www.ghacks.net/2012/09/04/list-of-chrome-urls-and-their-purpose/
While's there's a way to call a Windows command line function to retrieve the browser version details, e.g. How to get chrome version using command prompt in windows , the solution won't generalize and work on Mac OS / Linux.
You can use Pyppeteer as Selenium's alternative for accessing the chrome:// pages
pip install pyppeteer asyncio
Example for Windows OS:
from pyppeteer import launch
import time
import asyncio
import nest_asyncio
nest_asyncio.apply()
async def main():
browser = await launch({
"headless": False,
"executablePath": "C:/Program Files/Google/Chrome/Application/chrome.exe"
})
page = await browser.newPage()
await page.goto('chrome://settings/help')
time.sleep(3) # wait 3s
chromeVersion = await page.evaluate('''
document.querySelector('settings-ui')
.shadowRoot.querySelector('settings-main')
.shadowRoot.querySelector('settings-about-page')
.shadowRoot.querySelector('div.secondary').innerText
''')
await browser.close()
print(chromeVersion)
asyncio.get_event_loop().run_until_complete(main())
The output will correspond to your Chrome Application:
Version 112.0.5615.87 (Official Build) (64-bit)
For Linux/Mac, you can change executablePath based on the Chrome application's path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With