Urlib is one of the package of python which is used for scraping the webistes means getting data of website. Other than urlib , there is one more package named request which is most widely used than Urlib package. In this blog, will look at basic functions and functionality associated with this pacakge. In the upcoming blog, we will look how to do web scraping using BeautifulSoup and request package.

Let’s get started.

In url there are two types of Protocol Identifier -:

  1. http: Hyper Text Tranfer Protocol.
  2. https: Hyper Text Tranfer Protocol Secure. It is more safe than http.This keeps your information safe from hackers.

In [2]:

## From urlib pacakge, importing request method, urlopen method.
from urllib.request import Request, urlopen

## Requesting this URL
url = "https://www.google.com/"
req = Request(url)

## Getting Response after fetching the results from request.
res = urlopen(req)

## Returning the text or more specifically html file.
text = res.read()

In [3]:

print(text)

b'<!doctype html>