In python 3 urllib2 was merged into urllib. See also another Stack Overflow question and the urllib PEP 3108.
To make Python 2 code work in Python 3:
try:
import urllib.request as urllib2
except ImportError:
import urllib2
PYTHON 3
import urllib.request
wp = urllib.request.urlopen(“http://example.com”)
pw = wp.read()
print(pw)
PYTHON 2
import urllib
import sys
wp = urllib.urlopen(“http://example.com”)
for line in wp:
sys.stdout.write(line)
While I have tested both the Codes in respective versions.