'How to open a website in google chrome using webbrowser module

I am trying to open a website from python in google chrome, but when I run this code -

import webbrowser
webbrowser.open('youtube.com')

It opens Youtube in edge browser. Then I tried to change the default browser, but it still didn't work, so I ran this code:

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

But this code didn't give any output. So how can I open a website in google chrome using python.



Solution 1:[1]

Try this:

import webbrowser 

url = "https://www.youtube.com/"
webbrowser.open(url)

I use https://www.youtube.com/ instead of youtube.com and it will works :)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 arya sianati