URLLib (Python Internet Protocol Library)
Introduction
urllibis a Python Standard Library package that collects several modules for working with URLs:
urllib.requestfor opening and reading URLsurllib.errorcontaining the exceptions raised byurllib.requesturllib.parsefor parsing URLsurllib.robotparserfor parsingrobots.txtfiles
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)