你可以使用 Python 的 requests 库来发送 HTTP 请求,并使用 BeautifulSoup 库来解析 HTML 页面。下面是一个示例代码:
import requestsfrom bs4 import BeautifulSoup
url = 'https://www.souzhou.com/xingming/xingshi/'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
surnames = soup.find_all('a', class_='xl')
print([surname.text for surname in surnames])
这段代码会使用 requests 库发送 GET 请求爬取网页,使用 BeautifulSoup 解析网页,并获取所有类名为 xl 的 a 标签中的文本,这些文本就是百家姓。