Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does my default browser didn't open, instead microsoft edge is opened

Tags:

python-3.x

If i pass full web address like: https://gaana.com it opens through my default browser chrome. But when i pass, ganna.com , the web page is perfectly open through microsoft edge. Any help about why the browser changes?

import webbrowser

alink = input('Enter the name: ')
new = 2
webbrowser.open(alink, new=new)

There is no error in general, but browser changes from default(chrome) to microsoft edge browser

like image 456
Ayan Chowdhury Avatar asked May 20 '26 01:05

Ayan Chowdhury


1 Answers

That's most likely because your system doesn't know how to open the URL properly when no protocol was specified. Why don't you just prepend the protocol when the user has not passed any?

Example:

import webbrowser

alink = input('Enter the name: ')
new = 2

# protocol always comes before "://"
temp = alink.split('://')

if len(temp) > 2: # no protocol was specified
  # let's use HTTP then
  alink = "http://" + alink

webbrowser.open(alink, new=new)
like image 76
Telmo Trooper Avatar answered May 22 '26 15:05

Telmo Trooper