concept urlopen in category data

appears as: urlopen
Data Science Bookcamp: Five Python Projects

This is an excerpt from Manning's book Data Science Bookcamp: Five Python Projects.

The Beautiful Soup library allows to easily parse, analyze, and edit HTML documents. In most cases, these documents must be downloaded directly from the web. Lets briefly review the procedure for downloading HTML files, using Python’s built-in urllib module. We’ll start by importing the urlopen function from urllib.request.

The urlopen function is sufficient when downloading a single HTML document from a single, unsecured online page. However, for more complicated downloads, you should consider using the external Requests library. requests.readthedocs.io

Listing 16.34. Importing the urlopen function
from urllib.request import urlopen

Given the url of an online document, we can download the associated HTML contents by running urlopen(url).read(). Below, we’ll use urlopen to download the Manning website for this book. Afterwards, we’ll print the first 1000 characters of the downloaded HTML.