17_Ronstark_04
17_Ronstark_04

Reputation: 11

Python Webbrowser module not giving the desired output

Hey guys I'am testing a python module named 'webbrowser' but its not giving any responses when I tries to open youtube. Please solve this problem. This is the code.

import webbrowser

webbrowser.open("www.youtube.com")

And I'm not getting any error also. On Printing it is showing :

True

When I tried this code :

import webbrowser
webbrowser.get("google-chrome"),open("https://www.youtube.com")

It gives this error:

webbrowser.get("google-chrome"),open("https://www.youtube.com")  
File "C:\Program Files\Python39\lib\webbrowser.py", line 65, in get
raise Error("could not locate runnable browser")
webbrowser.Error: could not locate runnable browser

Upvotes: 1

Views: 1049

Answers (1)

Ali Irani
Ali Irani

Reputation: 607

Please locate your browser path and then register it through document, Then run the webbrowser.

import webbrowser    
urL='https://www.google.com'
chrome_path="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chrome_path), 1)
webbrowser.get('chrome').open(urL)

Upvotes: 1

Related Questions