0
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

2 Answers2

1

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

imkar
  • 9
  • 3
0
#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

amd
  • 342
  • 1
  • 2
  • 15
  • @S3DEV In the case of Windows, the path uses a UNIX-style path, so make the backslash into forwarding slashes. [check this answer](https://stackoverflow.com/a/31262561/15410147) – amd Jun 04 '22 at 14:16
  • The modulo 's' is used to give a command line that will split it into name and args according to [source code](https://github.com/python/cpython/blob/2.7/Lib/webbrowser.py#L34) – amd Jun 04 '22 at 15:36
  • 1
    Okay done :) I did it – amd Jun 04 '22 at 16:28