1#Used to make requests
2import urllib.request
3
4x = urllib.request.urlopen('https://www.google.com/')
5print(x.read())
1>>> import urllib3
2>>> http = urllib3.PoolManager()
3>>> r = http.request('GET', 'http://httpbin.org/robots.txt')
4>>> r.status
5200
6>>> r.data
7'User-agent: *\nDisallow: /deny\n'
8
1import urllib.request
2
3req = urllib.request.Request('http://www.voidspace.org.uk')
4with urllib.request.urlopen(req) as response:
5 the_page = response.read()
6
1#In Python 3.x, the urlretrieve function is located in the urllib.request module:
2from urllib.request import urlretrieve
1from urllib.request
2import urlopen
3story = urlopen('http://sixty-north.com/c/t.txt')
4story_words = []
5
6for line in story:
7 line_words = line.split()
8for word in line_words:
9 story_words.append(word)
10story.close()