how to open a url in python


Question

import urllib

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

But when example.com opens it does not render css or js. 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",)

1
60
3/3/2014 4:15:10 PM

Accepted Answer

with the webbrowser module

import webbrowser

webbrowser.open('http://example.com')  # Go to example.com
142
7/15/2016 8:44:34 PM

import webbrowser  
webbrowser.open(url, new=0, autoraise=True)

Display url using the default browser. If new is 0, the url is opened in the same browser window if possible. If new is 1, a new browser window is opened if possible. If new is 2, a new browser page (“tab”) is opened if possible. If autoraise is True, the window is raised

webbrowser.open_new(url)

Open url in a new window of the default browser

webbrowser.open_new_tab(url)

Open url in a new page (“tab”) of the default browser


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon