1from bs4 import BeautifulSoup
2
3# Simple HTML
4SIMPLE_HTML = '''<html>
5<head></head>
6<body>
7<h1>This is a title</h1>
8<p class="subtitle">Lorem ipsum dolor sit amet.</p>
9<p>Here's another p without a class</p>
10<ul>
11 <li>Sarah</li>
12 <li>Mary</li>
13 <li>Charlotte</li>
14 <li>Carl</li>
15</ul>
16</body>
17</html>'''
18
19simple_soup = BeautifulSoup(SIMPLE_HTML, 'html.parser') # use html.parser in order to understand the simple HTML
20
21# Find list from html
22def find_list():
23 list_items = simple_soup.find_all('li')
24 my_list = [e.string for e in list_items] # convert list_items to string
25 print(my_list)
26
27find_list()
28
29
30