URLLib (Python Internet Protocol Library)
Introduction
urllib
is a Python Standard Library package that collects several modules for working with URLs:
urllib.request
for opening and reading URLsurllib.error
containing the exceptions raised byurllib.request
urllib.parse
for parsing URLsurllib.robotparser
for parsingrobots.txt
files
Requesting Data from URL
Here is a simple example of using urllib.request
to
request the HTML for MIT's Course Catalog.
import urllib.request
import json
# request json file
url = 'http://student.mit.edu/catalog/m1a.html'
response = urllib.request.urlopen(url).read()
data = response.decode('utf-8')
# write to console
print(data)