构建基于重庆招生网的数据分析平台
2025-04-30 08:37

以下是示例代码片段:
import requests
from bs4 import BeautifulSoup
import pandas as pd
import matplotlib.pyplot as plt
# 发送请求并获取页面内容
url = "https://www.zhaoshengwang.com"
response = requests.get(url)
html_content = response.text
# 解析HTML文档
soup = BeautifulSoup(html_content, 'html.parser')
data_rows = []
# 提取表格中的数据
table = soup.find('table')
for row in table.find_all('tr'):
cols = row.find_all('td')
data_rows.append([col.text.strip() for col in cols])
# 转换为DataFrame
df = pd.DataFrame(data_rows[1:], columns=data_rows[0])
print(df.head())
# 数据可视化
plt.figure(figsize=(10, 6))
plt.bar(df['School'], df['Enrollment'])
plt.title("重庆各高校招生人数统计")
plt.xlabel("学校名称")
plt.ylabel("招生人数")
plt.xticks(rotation=90)
plt.show()
通过上述方法,我们可以有效地从重庆招生网提取数据,并对其进行深入分析,为用户提供有价值的参考信息。
]]>
本站知识库部分内容及素材来源于互联网,如有侵权,联系必删!
标签:招生网

