BeautifulSoup Scraping List from HTML (original) (raw)

Last Updated : 23 Jul, 2025

Prerequisite:

Python can be employed to scrap information from a web page. It can also be used to retrieve data provided within a specific tag, this article how list elements can be scraped from HTML.

Module Needed:

pip install bs4

pip install requests

Approach:

Example 1: Scraping List from HTML Code

Python3 `

Import Required Modules

from bs4 import BeautifulSoup import requests

HTML Code

html_content = """

"""

Parse the html content

soup = BeautifulSoup(html_content, "lxml")

Find all li tag

datas = soup.find_all("li")

Iterate through all li tags

for data in datas: # Get text from each tag print(data.text)

print(f"Total {len(datas)} li tag found")

`

Output:

Coffee

Tea

Milk

Total 3 li tag found

Example 2: Scraping List from Web URL

Python3 `

Import Required Modules

from bs4 import BeautifulSoup import requests

HTML Code

html_content = """

"""

Parse the html content

soup = BeautifulSoup(html_content, "lxml")

Find all li tag

datas = soup.find_all("li")

Iterate through all li tags

for data in datas: # Get text from each tag print(data.text)

print(f"Total {len(datas)} li tag found")

`

Output: