/    /  Python – Internet access

Python – Internet access:

In this tutorial, we will learn about how to access the internet using the python. In python, we will have a module called “urllib” that provides various Objects and functions to access the internet.

We can perform many activities using this “urllib” module like accessing the webpage data of any website, sending an email… etc.

Let us try fetching the 100 bytes of code behind the google.com page. Below is the example.

Example:

>>> import urllib.request

>>> f = urllib.request.urlopen("http://google.com/")

>>> print(f.read(100).decode('utf-8'))

Output:

<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en-IN"><head><meta cont

Let us try fetching the 500 bytes of code behind the google.com page.

>>> print(f.read(500).decode('utf-8'))

Output:

ent="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/logos/doodles/2017/sitara-devis-97th-birthday-6469056130449408.5-l.png" itemprop="image"><meta content="Sitara Devi&#8217;s 97th birthday" property="twitter:title"><meta content="Celebrating Sitara Devi&#8217;s 97th birthday! #GoogleDoodle" property="twitter:description"><meta content="Celebrating Sitara Devi&#8217;s 97th birthday! #GoogleDoodle" property="og:description"><meta content="summary_large_image" property="twitte