今天是第十七天,來學習Beautiful Soup吧!
Beautiful Soup是Python中一個強大的函數庫,用於解析和提取HTML和XML中的數據。今天,我們將學習如何使用Beautiful Soup。
pip install beautifulsoup4
import requests
from bs4 import BeautifulSoup
url = 'https://example.com'
response = requests.get(url)
html_content = response.text
soup = BeautifulSoup(html_content, 'html.parser')
title = soup.title.text print("網頁標題:", title)
paragraphs = soup.find_all('p') for para in paragraphs: print(para.text)