Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.5 urllib won't open webpage in browser

I tried following code in VS2015, Eclipse and Spyder:

import urllib.request
with urllib.request.urlopen('https://www.python.org/') as response:
    html = response.read()

In call cases it won't open the webpage in the browser. I am not sure what is the problem. Debug won't help. In VS2015 the program exists with code 0 which I suppose means successful.

like image 718
algoProg Avatar asked Nov 27 '25 21:11

algoProg


1 Answers

You are using wrong library for the job. urllib module provides functions to send http requests and capture the result in your program. It has nothing to do with a web browser. What you are looking for is the webbrowser module. Here is an example:

import webbrowser
webbrowser.open('http://google.com')

This will show the web page in your browser.

like image 134
HeyYO Avatar answered Nov 29 '25 10:11

HeyYO



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!