Fix Python – How to open a URL in python

Question

Asked By – shamsee

import urllib

fun open():
    return urllib.urlopen('http://example.com')

But when example.com opens it does not render CSS or JavaScript. How can I open the webpage in a web browser?

@error(404)
def error404(error):
    return webbrowser.open('http://example.com')

I am using bottle. Giving me the error:

TypeError("'bool' object is not iterable",)

Now we will see solution for issue: How to open a URL in python


Answer

with the webbrowser module

import webbrowser

webbrowser.open('http://example.com')  # Go to example.com

This question is answered By – aaronasterling

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0