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.

1 answer

  • answered 2022-05-04 11:11 arya sianati

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

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum