Web Content Downloader

Write a Python program that takes a URL and downloads the content of the webpage. The program should handle exceptions for with time, like invalid URL, no internet connection, etc.

Example 1:

Input: "https://www.example.com"
Output: "<!doctype html>..."

Example 2:

Input:"https://www.example.com/"
Output: "Exception: Invalid URL"

Use Python’s requests module to download the webpage.

import requests

def download_webpage_content(url):
    try:
        response = requests.get(url)
        response.raise_for_status()
        return response.text
    except requests.exceptions.RequestException as e:
        return "Exception: Invalid URL or no internet connection"

 

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!