solution_041.py

#! /usr/bin/python3
# ===================================================================
# www.dataquest.io/blog/web-scraping-tutorial-python/
# www.geeksforgeeks.org/implementing-web-scraping-python-beautiful-soup/
# www.crummy.com/software/BeautifulSoup/bs4/doc/
# ===================================================================

import requests

from bs4 import BeautifulSoup as bs

import sys

# -------------------------------------------------------------------
# ---- global data
# -------------------------------------------------------------------

URL =  "http://localhost/index.html"

# -------------------------------------------------------------------
# ---- main
# -------------------------------------------------------------------

if __name__ == '__main__':

    # ---- request web page (URL)

    page = requests.get(URL)

    print(f'Request status code is {page.status_code}')

    if not page.status_code == 200:
        print('Error: request web page failed')
        print(URL)
        sys.exit()

    # ---- If this line causes an error, run 'pip install html5lib'
 
    soup = bs(page.content, 'html5lib')

    print(soup.prettify())

    ##soup = bs(page.content,'html.parser')