Python 3 BeautifulSoup4 Script to Extract All H1,H2 & H3 Tags in Given HTML5 Webpage Full Project For Beginners

 

 

pip install bs4

 

 

app.py

 

 

import requests
from bs4 import BeautifulSoup
url = 'https://www.python.org/'
reqs = requests.get(url)
soup = BeautifulSoup(reqs.text, 'lxml')
print("List of all the h1, h2, h3 :")
for heading in soup.find_all(["h1", "h2", "h3"]):
    print(heading.name + ' ' + heading.text.strip())

Leave a Reply