Python Webbrowser module not giving the desired output

Viewed 223

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
1 Answers

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)
Related