Angadpal Tak
Angadpal Tak

Reputation: 77

How do I open google chrome in python

I have tried to do various python codes but I cannot find any that work on my PC.

def UI():
os.system('cls' if os.name == 'nt' else 'clear')
choice1=input("Pick a program: ")
if choice1=='Google':   
 ('https://www.google.com/')

That is all I have come up with

If anybody has any answers please tell me

Upvotes: 3

Views: 3073

Answers (2)

Denis Tereshchenko
Denis Tereshchenko

Reputation: 131

Use os.system('start chrome') and os.system('start chrome {}'.format(site)) in Windows or os.system('google-chrome') and os.system('google-chrome {}'.format(site)) in Linux, where site is URL for the site you're looking for.

Upvotes: 2

Ramanjaneyalu T
Ramanjaneyalu T

Reputation: 36

import webbrowser

url = 'http://docs.python.org/'

# MacOS
chrome_path = 'open -a /Applications/Google\ Chrome.app %s'

# Windows
# chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'

# Linux
# chrome_path = '/usr/bin/google-chrome %s'

webbrowser.get(chrome_path).open(url)

You can call get() with the path to Chrome. Below is an example - replace chrome_path with the correct path for your platform.

Upvotes: 1

Related Questions