Tutorial Example

Fix ImportError: No module named ‘urllib2’ in Python 3.5 – Python Tutorial

urllib2 is used in python 2.x, so if you use urllib2 in python 3.x, you will get this error: No module named ‘urllib2’. To fix this error, we should use python 2.x or replace urllib.request to replace it.

urllib library in python 3.x contains:

Here is an example for using urllib.request.

import urllib.request
with urllib.request.urlopen('http://www.python.org/') as f:
    print(f.read(300))