```py
from bs4 import BeautifulSoup
html = """
<html>
<head>
<title>Example</title>
</head>
<body>
<h1>Example</h1>
<p>Paragraph 1</p>
<p>Paragraph 2</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</body>
</html>
"""
# 創建 BeautifulSoup 對象
soup = BeautifulSoup(html, 'html.parser')
# 獲取 title 元素的內容
title = soup.title.string
print(title) # "Example"
# 獲取所有 p 元素的內容
ps = soup.find_all('p')
for p in ps:
print(p.string)
# 獲取第一個 li 元素的內容
li = soup.find('li')
print(li.string)
```
```py
from bs4 import BeautifulSoup
html = """
<html>
<head>
<title>Example</title>
</head>
<body>
<h1>Example</h1>
<p>Paragraph 1</p>
<p>Paragraph 2</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</body>
</html>
"""
soup = BeautifulSoup(html, 'html.parser')
# 獲取第一個 p 元素對象
p1 = soup.find('p')
# 獲取第二個 p 元素對象
p2 = p1.find_next('p')
print(p1.string) # "Paragraph 1"
print(p2.string) # "Paragraph 2"
```
```py
from bs4 import BeautifulSoup
# 範例 HTML
html = """
<div class="item checked">Item 1</div>
<div class="item">Item 2</div>
<div class="item checked">Item 3</div>
"""
# 將 HTML 轉為 BeautifulSoup 物件
soup = BeautifulSoup(html, 'html.parser')
# 找到 class 屬性值包含 checked 的 div 標籤
div_list = soup.find_all('div', {'class': lambda x: x and 'checked' in x})
# 列印結果
for div in div_list:
print(div.text)
```