Abhinav Gupta
Abhinav Gupta

Reputation: 1

I cannot open chrome with webbrowser in python

import webbrowser
chrome_path="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
webbrowser.get(chrome_path).open("youtube.com")

this is the code that I wrote and this gives an error that it could not locate a runnable browser

Upvotes: 0

Views: 1023

Answers (2)

amd
amd

Reputation: 364

#Chnage this:

chrome_path="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"

#To:

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

#OR:

chrome_path= r"C:\\Program Files(x86)\\Google\\Chrome\\Application\\chrome.exe %s"

PS - The modulo 's' is used to give a command line that will split it into name and args according to source code

Upvotes: 0

imkar
imkar

Reputation: 9

As i see from the documentation, you do not have to give full path to your browsers executable.

You can use:

import webbrowser
webbrowser.get('chrome').open("youtube.com")

documentation link: https://docs.python.org/3/library/webbrowser.html

Upvotes: 1

Related Questions