0
import webbrowser

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

webbrowser.get(Chrome).open("haveibeenpwned.com")

Whenever I try I get this "could not locate runnable browser"

P.S: I'm tryna learn python

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Several
  • 5
  • 3
  • As @"Erec Aizen" stated, it is better to use the unix style notation (like also often used in java). If you want to use backslashes, you should at least either double the backslashes or mark the path string as raw string, so python does not interpret the backslashes as escape chars. This means, just add a r directly before the string `Chrome=r'C\Program...`. Just try `print('c:\Program Files (x86)\newDir')` in python and see, what happens. – jottbe Oct 05 '20 at 20:56
  • Does this answer your question? [Python: generic webbrowser.get().open() for chrome.exe does not work](https://stackoverflow.com/questions/24873302/python-generic-webbrowser-get-open-for-chrome-exe-does-not-work) – lupodellasleppa Jan 21 '21 at 16:39

3 Answers3

0

You should register it first.

webbrowser.register('chrome', None,webbrowser.BackgroundBrowser(Chrome), 1)
webbrowser.get('chrome').open_new_tab("haveibeenpwned.com")
akiva
  • 369
  • 1
  • 9
0

You should use UNIX-style path: common slashes instead of backslashes.

import webbrowser

chrome = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'

webbrowser.get(chrome).open("haveibeenpwned.com")
0

Seems like the problem is the spaces in your path. You need to insert a final %s at the end of your path to make it work. No need to register the browser name first.

webbrowser.get(
    "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
).open("haveibeenpwned.com")

As seen here: Python: generic webbrowser.get().open() for chrome.exe does not work

lupodellasleppa
  • 124
  • 1
  • 1
  • 11