上传文件至 /

This commit is contained in:
2026-06-23 10:25:13 +08:00
parent 711fdcda9c
commit 0bae8e0060
4 changed files with 334 additions and 0 deletions

152
movies.html Normal file
View File

@@ -0,0 +1,152 @@
<!-- exam_fingerprint: B-20260623-9063 -->
<!-- server_time: 2026-06-23 10:04:45 -->
<!-- exam_paper: B -->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>电影列表</title>
<style>
body { font-family: "Microsoft YaHei", sans-serif; margin: 20px; background: #f5f5f5; }
h1 { color: #c0392b; }
.meta { color: #999; font-size: 12px; margin-bottom: 15px; }
.meta code { background: #e9ecef; padding: 2px 6px; border-radius: 3px; }
table { width: 100%; border-collapse: collapse; background: white; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
th, td { padding: 10px; text-align: left; border-bottom: 1px solid #ddd; }
th { background: #c0392b; color: white; }
tr:hover { background: #fef5f4; }
</style>
</head>
<body>
<h1>电影列表</h1>
<p class="meta">数据编号:<code>B-20260623-9063</code></p>
<table>
<thead>
<tr>
<th>编号</th>
<th>电影名</th>
<th>导演</th>
<th>上映年份</th>
<th>评分</th>
<th>时长(分钟)</th>
<th>类型</th>
<th>主演数</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>霸王别姬</td>
<td>Frank Darabont</td>
<td>2021</td>
<td>6.1</td>
<td>120</td>
<td>冒险</td>
<td>2</td>
</tr>
<tr>
<td>2</td>
<td>放牛班的春天</td>
<td>陈凯歌</td>
<td>2012</td>
<td>7.2</td>
<td>131</td>
<td>科幻</td>
<td>4</td>
</tr>
<tr>
<td>3</td>
<td>星际穿越</td>
<td>Robert Zemeckis</td>
<td>1992</td>
<td>8.3</td>
<td>93</td>
<td>冒险</td>
<td>2</td>
</tr>
<tr>
<td>4</td>
<td>盗梦空间</td>
<td>James Cameron</td>
<td>1998</td>
<td>8.9</td>
<td>127</td>
<td>剧情</td>
<td>2</td>
</tr>
<tr>
<td>5</td>
<td>千与千寻</td>
<td>宫崎骏</td>
<td>2012</td>
<td>7.2</td>
<td>113</td>
<td>动画</td>
<td>4</td>
</tr>
<tr>
<td>6</td>
<td>阿甘正传</td>
<td>Christopher Nolan</td>
<td>1991</td>
<td>7.8</td>
<td>140</td>
<td>喜剧</td>
<td>5</td>
</tr>
<tr>
<td>7</td>
<td>肖申克的救赎</td>
<td>Lasse Hallström</td>
<td>2015</td>
<td>7.8</td>
<td>111</td>
<td>科幻</td>
<td>2</td>
</tr>
<tr>
<td>8</td>
<td>忠犬八公的故事</td>
<td>Rajkumar Hirani</td>
<td>2014</td>
<td>9.3</td>
<td>105</td>
<td>喜剧</td>
<td>3</td>
</tr>
<tr>
<td>9</td>
<td>泰坦尼克号</td>
<td>Christophe Barratier</td>
<td>2022</td>
<td>9.4</td>
<td>130</td>
<td>剧情</td>
<td>3</td>
</tr>
<tr>
<td>10</td>
<td>三傻大闹宝莱坞</td>
<td>Christopher Nolan</td>
<td>2021</td>
<td>7.6</td>
<td>145</td>
<td>科幻</td>
<td>4</td>
</tr>
</tbody>
</table>
</body>
</html>

105
movies.json Normal file
View File

@@ -0,0 +1,105 @@
{
"data_id": 1,
"movies": [
{
"id": 1,
"title": "霸王别姬",
"director": "Frank Darabont",
"year": 2021,
"rating": 6.1,
"duration": 120,
"genre": "冒险",
"actors_count": 2
},
{
"id": 2,
"title": "放牛班的春天",
"director": "陈凯歌",
"year": 2012,
"rating": 7.2,
"duration": 131,
"genre": "科幻",
"actors_count": 4
},
{
"id": 3,
"title": "星际穿越",
"director": "Robert Zemeckis",
"year": 1992,
"rating": 8.3,
"duration": 93,
"genre": "冒险",
"actors_count": 2
},
{
"id": 4,
"title": "盗梦空间",
"director": "James Cameron",
"year": 1998,
"rating": 8.9,
"duration": 127,
"genre": "剧情",
"actors_count": 2
},
{
"id": 5,
"title": "千与千寻",
"director": "宫崎骏",
"year": 2012,
"rating": 7.2,
"duration": 113,
"genre": "动画",
"actors_count": 4
},
{
"id": 6,
"title": "阿甘正传",
"director": "Christopher Nolan",
"year": 1991,
"rating": 7.8,
"duration": 140,
"genre": "喜剧",
"actors_count": 5
},
{
"id": 7,
"title": "肖申克的救赎",
"director": "Lasse Hallström",
"year": 2015,
"rating": 7.8,
"duration": 111,
"genre": "科幻",
"actors_count": 2
},
{
"id": 8,
"title": "忠犬八公的故事",
"director": "Rajkumar Hirani",
"year": 2014,
"rating": 9.3,
"duration": 105,
"genre": "喜剧",
"actors_count": 3
},
{
"id": 9,
"title": "泰坦尼克号",
"director": "Christophe Barratier",
"year": 2022,
"rating": 9.4,
"duration": 130,
"genre": "剧情",
"actors_count": 3
},
{
"id": 10,
"title": "三傻大闹宝莱坞",
"director": "Christopher Nolan",
"year": 2021,
"rating": 7.6,
"duration": 145,
"genre": "科幻",
"actors_count": 4
}
]
}

34
q2_1.py Normal file
View File

@@ -0,0 +1,34 @@
import requests
from bs4 import BeautifulSoup as bs
import json
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
"AppleWebKit/537.36 (KHTML, like Gecko)"
"Chrome/129.0.0.0 Safari/537.36"
}
url = "https://exam.detr.top/exam-b/movies"
data = []
resp = requests.get(url, headers=headers)
resp.encoding = 'utf-8'
html_content = resp.text
with open("movies.html", "w", encoding="utf-8") as f:
f.write(html_content)
soup = bs(html_content, "html.parser")
movies = []
table = soup.find("table")
rows = table.find_all("tr")[1:]
for row in rows:
cols = row.find_all("td")
movie = {
"id": int(cols[0].text.strip()),
"title": cols[1].text.strip(),
"director": cols[2].text.strip(),
"year": int(cols[3].text.strip()),
"rating": float(cols[4].text.strip()),
"duration": int(cols[5].text.strip()),
"genre": cols[6].text.strip(),
"actors_count": int(cols[7].text.strip())
}
movies.append(movie)
with open("movies.json", "w", encoding="utf-8") as f:
json.dump({"data_id": 1, "movies": movies}, f, ensure_ascii=False, indent=4)

43
q2_2.py Normal file
View File

@@ -0,0 +1,43 @@
import json
# 读取本地json文件
with open("movies.json", "r", encoding="utf-8") as f:
data = json.load(f)
movie_list = data["movies"]
# ① 找出评分最高、最低电影并打印
ratings = [m["rating"] for m in movie_list]
max_rating = max(ratings)
min_rating = min(ratings)
max_movies = [m for m in movie_list if m["rating"] == max_rating]
min_movies = [m for m in movie_list if m["rating"] == min_rating]
print("===== 1. 评分极值电影 =====")
print("评分最高的电影:")
for m in max_movies:
print(f"{m['title']} - {m['rating']}")
print("评分最低的电影:")
for m in min_movies:
print(f"{m['title']} - {m['rating']}")
# ② 统计各类型电影数量
genre_count = {}
for m in movie_list:
g = m["genre"]
genre_count[g] = genre_count.get(g, 0) + 1
print("\n===== 2. 各类型电影数量 =====")
print(genre_count)
# ③ 统计各导演电影数量
director_count = {}
for m in movie_list:
d = m["director"]
director_count[d] = director_count.get(d, 0) + 1
print("\n===== 3. 各导演电影数量 =====")
print(director_count)
# ④ 统计2020年后上映电影数量
count_after_2020 = sum(1 for m in movie_list if m["year"] >= 2020)
print("\n===== 4. 2020年(含)后上映电影总数 =====")
print(count_after_2020)