Compare commits

4 Commits
main ... main

Author SHA1 Message Date
59495f7500 提交 2026-06-25 16:18:22 +08:00
04c510a471 3-3-2 2026-06-25 15:56:06 +08:00
62b937b757 3-3-1 2026-06-25 15:52:36 +08:00
85b531e464 1 2026-06-25 15:47:41 +08:00
18 changed files with 773 additions and 0 deletions

30
q2_1_crawler/1.py Normal file
View File

@@ -0,0 +1,30 @@
import re
import requests
from bs4 import BeautifulSoup as bs
import json
header = {'User-Agent':'Mozilla/5.0'}
url = 'https://exam.detr.top/exam-b/movies'
html = requests.get(url, headers=header).text
# print(html)
open('movies.html','w',encoding='utf-8').write(html)
# print(html)
# print('==============')
# fd = bs(html, 'html.parser').find('p', class_='meta')
fd = re.search(r'exam_fingerprint:\s*(\S+)',html).group(1)
# print(fd)
resp = bs(html, 'html.parser').find_all('tr', class_='item-row')
# print(resp)
movies = []
for i in resp:
c = []
for r in i.find_all('td'):
c.append(r.text.strip())
movies.append({
'id':int(c[0]), 'title':c[1], 'director':c[2], 'year':int(c[3]), 'rating':float(c[4]), 'duration':int(c[5]), 'genre':c[6], 'actors_count':int(c[7])
})
json.dump({'ID':fd, 'movies':movies}, open('movies.json', 'w', encoding='utf-8'), ensure_ascii=False, indent=2)

152
q2_1_crawler/movies.html Normal file
View File

@@ -0,0 +1,152 @@
<!-- exam_fingerprint: B-20260625-3464 -->
<!-- server_time: 2026-06-25 15:42:14 -->
<!-- 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-20260625-3464</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 class="item-row">
<td class="item-id">1</td>
<td class="item-title">霸王别姬</td>
<td class="item-director">Frank Darabont</td>
<td class="item-year">2004</td>
<td class="item-rating">6.8</td>
<td class="item-duration">179</td>
<td class="item-genre">科幻</td>
<td class="item-actors-count">3</td>
</tr>
<tr class="item-row">
<td class="item-id">2</td>
<td class="item-title">放牛班的春天</td>
<td class="item-director">陈凯歌</td>
<td class="item-year">2019</td>
<td class="item-rating">6.7</td>
<td class="item-duration">117</td>
<td class="item-genre">喜剧</td>
<td class="item-actors-count">5</td>
</tr>
<tr class="item-row">
<td class="item-id">3</td>
<td class="item-title">泰坦尼克号</td>
<td class="item-director">Robert Zemeckis</td>
<td class="item-year">2015</td>
<td class="item-rating">9.1</td>
<td class="item-duration">177</td>
<td class="item-genre">爱情</td>
<td class="item-actors-count">4</td>
</tr>
<tr class="item-row">
<td class="item-id">4</td>
<td class="item-title">三傻大闹宝莱坞</td>
<td class="item-director">James Cameron</td>
<td class="item-year">2024</td>
<td class="item-rating">7.6</td>
<td class="item-duration">117</td>
<td class="item-genre">冒险</td>
<td class="item-actors-count">5</td>
</tr>
<tr class="item-row">
<td class="item-id">5</td>
<td class="item-title">阿甘正传</td>
<td class="item-director">宫崎骏</td>
<td class="item-year">2016</td>
<td class="item-rating">8.0</td>
<td class="item-duration">146</td>
<td class="item-genre">喜剧</td>
<td class="item-actors-count">3</td>
</tr>
<tr class="item-row">
<td class="item-id">6</td>
<td class="item-title">星际穿越</td>
<td class="item-director">Christopher Nolan</td>
<td class="item-year">2010</td>
<td class="item-rating">9.2</td>
<td class="item-duration">168</td>
<td class="item-genre">爱情</td>
<td class="item-actors-count">2</td>
</tr>
<tr class="item-row">
<td class="item-id">7</td>
<td class="item-title">忠犬八公的故事</td>
<td class="item-director">Lasse Hallström</td>
<td class="item-year">2016</td>
<td class="item-rating">9.3</td>
<td class="item-duration">106</td>
<td class="item-genre">悬疑</td>
<td class="item-actors-count">5</td>
</tr>
<tr class="item-row">
<td class="item-id">8</td>
<td class="item-title">肖申克的救赎</td>
<td class="item-director">Rajkumar Hirani</td>
<td class="item-year">2018</td>
<td class="item-rating">7.3</td>
<td class="item-duration">107</td>
<td class="item-genre">剧情</td>
<td class="item-actors-count">4</td>
</tr>
<tr class="item-row">
<td class="item-id">9</td>
<td class="item-title">千与千寻</td>
<td class="item-director">Christophe Barratier</td>
<td class="item-year">2019</td>
<td class="item-rating">7.3</td>
<td class="item-duration">118</td>
<td class="item-genre">动画</td>
<td class="item-actors-count">4</td>
</tr>
<tr class="item-row">
<td class="item-id">10</td>
<td class="item-title">盗梦空间</td>
<td class="item-director">Christopher Nolan</td>
<td class="item-year">2008</td>
<td class="item-rating">9.3</td>
<td class="item-duration">111</td>
<td class="item-genre">动画</td>
<td class="item-actors-count">5</td>
</tr>
</tbody>
</table>
</body>
</html>

105
q2_1_crawler/movies.json Normal file
View File

@@ -0,0 +1,105 @@
{
"ID": "B-20260625-3464",
"movies": [
{
"id": 1,
"title": "霸王别姬",
"director": "Frank Darabont",
"year": 2004,
"rating": 6.8,
"duration": 179,
"genre": "科幻",
"actors_count": 3
},
{
"id": 2,
"title": "放牛班的春天",
"director": "陈凯歌",
"year": 2019,
"rating": 6.7,
"duration": 117,
"genre": "喜剧",
"actors_count": 5
},
{
"id": 3,
"title": "泰坦尼克号",
"director": "Robert Zemeckis",
"year": 2015,
"rating": 9.1,
"duration": 177,
"genre": "爱情",
"actors_count": 4
},
{
"id": 4,
"title": "三傻大闹宝莱坞",
"director": "James Cameron",
"year": 2024,
"rating": 7.6,
"duration": 117,
"genre": "冒险",
"actors_count": 5
},
{
"id": 5,
"title": "阿甘正传",
"director": "宫崎骏",
"year": 2016,
"rating": 8.0,
"duration": 146,
"genre": "喜剧",
"actors_count": 3
},
{
"id": 6,
"title": "星际穿越",
"director": "Christopher Nolan",
"year": 2010,
"rating": 9.2,
"duration": 168,
"genre": "爱情",
"actors_count": 2
},
{
"id": 7,
"title": "忠犬八公的故事",
"director": "Lasse Hallström",
"year": 2016,
"rating": 9.3,
"duration": 106,
"genre": "悬疑",
"actors_count": 5
},
{
"id": 8,
"title": "肖申克的救赎",
"director": "Rajkumar Hirani",
"year": 2018,
"rating": 7.3,
"duration": 107,
"genre": "剧情",
"actors_count": 4
},
{
"id": 9,
"title": "千与千寻",
"director": "Christophe Barratier",
"year": 2019,
"rating": 7.3,
"duration": 118,
"genre": "动画",
"actors_count": 4
},
{
"id": 10,
"title": "盗梦空间",
"director": "Christopher Nolan",
"year": 2008,
"rating": 9.3,
"duration": 111,
"genre": "动画",
"actors_count": 5
}
]
}

Binary file not shown.

File diff suppressed because one or more lines are too long

1
q3/q3_3_质量自评.md Normal file
View File

@@ -0,0 +1 @@

105
q4/q4_1/movies.json Normal file
View File

@@ -0,0 +1,105 @@
{
"ID": "B-20260625-3464",
"movies": [
{
"id": 1,
"title": "霸王别姬",
"director": "Frank Darabont",
"year": 2004,
"rating": 6.8,
"duration": 179,
"genre": "科幻",
"actors_count": 3
},
{
"id": 2,
"title": "放牛班的春天",
"director": "陈凯歌",
"year": 2019,
"rating": 6.7,
"duration": 117,
"genre": "喜剧",
"actors_count": 5
},
{
"id": 3,
"title": "泰坦尼克号",
"director": "Robert Zemeckis",
"year": 2015,
"rating": 9.1,
"duration": 177,
"genre": "爱情",
"actors_count": 4
},
{
"id": 4,
"title": "三傻大闹宝莱坞",
"director": "James Cameron",
"year": 2024,
"rating": 7.6,
"duration": 117,
"genre": "冒险",
"actors_count": 5
},
{
"id": 5,
"title": "阿甘正传",
"director": "宫崎骏",
"year": 2016,
"rating": 8.0,
"duration": 146,
"genre": "喜剧",
"actors_count": 3
},
{
"id": 6,
"title": "星际穿越",
"director": "Christopher Nolan",
"year": 2010,
"rating": 9.2,
"duration": 168,
"genre": "爱情",
"actors_count": 2
},
{
"id": 7,
"title": "忠犬八公的故事",
"director": "Lasse Hallström",
"year": 2016,
"rating": 9.3,
"duration": 106,
"genre": "悬疑",
"actors_count": 5
},
{
"id": 8,
"title": "肖申克的救赎",
"director": "Rajkumar Hirani",
"year": 2018,
"rating": 7.3,
"duration": 107,
"genre": "剧情",
"actors_count": 4
},
{
"id": 9,
"title": "千与千寻",
"director": "Christophe Barratier",
"year": 2019,
"rating": 7.3,
"duration": 118,
"genre": "动画",
"actors_count": 4
},
{
"id": 10,
"title": "盗梦空间",
"director": "Christopher Nolan",
"year": 2008,
"rating": 9.3,
"duration": 111,
"genre": "动画",
"actors_count": 5
}
]
}

19
q4/q4_1/q4_1.py Normal file
View File

@@ -0,0 +1,19 @@
import json
import matplotlib.pyplot as plt
movies = json.load(open('movies.json', encoding='utf-8'))['movies']
# print(movies)
genres = {}
for m in movies:
g = m['genre']
if g in genres:
genres[g] = genres[g] + 1
else:
genres[g] = 1
print(genres)
plt.figure(figsize=(8,5))
plt.bar(genres.keys(), genres.values())
plt.title('类型电影数量分布')
plt.xlabel('类型')
plt.ylabel('数量')
plt.savefig('q4_1_bar.png', dpi=150)

BIN
q4/q4_1/q4_1_bar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

105
q4/q4_2/movies.json Normal file
View File

@@ -0,0 +1,105 @@
{
"ID": "B-20260625-3464",
"movies": [
{
"id": 1,
"title": "霸王别姬",
"director": "Frank Darabont",
"year": 2004,
"rating": 6.8,
"duration": 179,
"genre": "科幻",
"actors_count": 3
},
{
"id": 2,
"title": "放牛班的春天",
"director": "陈凯歌",
"year": 2019,
"rating": 6.7,
"duration": 117,
"genre": "喜剧",
"actors_count": 5
},
{
"id": 3,
"title": "泰坦尼克号",
"director": "Robert Zemeckis",
"year": 2015,
"rating": 9.1,
"duration": 177,
"genre": "爱情",
"actors_count": 4
},
{
"id": 4,
"title": "三傻大闹宝莱坞",
"director": "James Cameron",
"year": 2024,
"rating": 7.6,
"duration": 117,
"genre": "冒险",
"actors_count": 5
},
{
"id": 5,
"title": "阿甘正传",
"director": "宫崎骏",
"year": 2016,
"rating": 8.0,
"duration": 146,
"genre": "喜剧",
"actors_count": 3
},
{
"id": 6,
"title": "星际穿越",
"director": "Christopher Nolan",
"year": 2010,
"rating": 9.2,
"duration": 168,
"genre": "爱情",
"actors_count": 2
},
{
"id": 7,
"title": "忠犬八公的故事",
"director": "Lasse Hallström",
"year": 2016,
"rating": 9.3,
"duration": 106,
"genre": "悬疑",
"actors_count": 5
},
{
"id": 8,
"title": "肖申克的救赎",
"director": "Rajkumar Hirani",
"year": 2018,
"rating": 7.3,
"duration": 107,
"genre": "剧情",
"actors_count": 4
},
{
"id": 9,
"title": "千与千寻",
"director": "Christophe Barratier",
"year": 2019,
"rating": 7.3,
"duration": 118,
"genre": "动画",
"actors_count": 4
},
{
"id": 10,
"title": "盗梦空间",
"director": "Christopher Nolan",
"year": 2008,
"rating": 9.3,
"duration": 111,
"genre": "动画",
"actors_count": 5
}
]
}

17
q4/q4_2/q4_2.py Normal file
View File

@@ -0,0 +1,17 @@
import json
import matplotlib.pyplot as plt
movies = json.load(open('movies.json', encoding='utf-8'))['movies']
# print(movies)
ratings = []
durations = []
for m in movies:
ratings.append(m['rating'])
durations.append(m['duration'])
plt.figure(figsize=(8,5))
plt.scatter(durations,ratings,color='red',alpha=0.6)
plt.title('时长与评分关系散点图')
plt.xlabel('duration')
plt.ylabel('rating')
plt.savefig('q4_2_scatter.png', dpi=150)

BIN
q4/q4_2/q4_2_scatter.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

105
q4/q4_3a/movies.json Normal file
View File

@@ -0,0 +1,105 @@
{
"ID": "B-20260625-3464",
"movies": [
{
"id": 1,
"title": "霸王别姬",
"director": "Frank Darabont",
"year": 2004,
"rating": 6.8,
"duration": 179,
"genre": "科幻",
"actors_count": 3
},
{
"id": 2,
"title": "放牛班的春天",
"director": "陈凯歌",
"year": 2019,
"rating": 6.7,
"duration": 117,
"genre": "喜剧",
"actors_count": 5
},
{
"id": 3,
"title": "泰坦尼克号",
"director": "Robert Zemeckis",
"year": 2015,
"rating": 9.1,
"duration": 177,
"genre": "爱情",
"actors_count": 4
},
{
"id": 4,
"title": "三傻大闹宝莱坞",
"director": "James Cameron",
"year": 2024,
"rating": 7.6,
"duration": 117,
"genre": "冒险",
"actors_count": 5
},
{
"id": 5,
"title": "阿甘正传",
"director": "宫崎骏",
"year": 2016,
"rating": 8.0,
"duration": 146,
"genre": "喜剧",
"actors_count": 3
},
{
"id": 6,
"title": "星际穿越",
"director": "Christopher Nolan",
"year": 2010,
"rating": 9.2,
"duration": 168,
"genre": "爱情",
"actors_count": 2
},
{
"id": 7,
"title": "忠犬八公的故事",
"director": "Lasse Hallström",
"year": 2016,
"rating": 9.3,
"duration": 106,
"genre": "悬疑",
"actors_count": 5
},
{
"id": 8,
"title": "肖申克的救赎",
"director": "Rajkumar Hirani",
"year": 2018,
"rating": 7.3,
"duration": 107,
"genre": "剧情",
"actors_count": 4
},
{
"id": 9,
"title": "千与千寻",
"director": "Christophe Barratier",
"year": 2019,
"rating": 7.3,
"duration": 118,
"genre": "动画",
"actors_count": 4
},
{
"id": 10,
"title": "盗梦空间",
"director": "Christopher Nolan",
"year": 2008,
"rating": 9.3,
"duration": 111,
"genre": "动画",
"actors_count": 5
}
]
}

14
q4/q4_3a/q4_3a.py Normal file
View File

@@ -0,0 +1,14 @@
import json
import matplotlib.pyplot as plt
movies = json.load(open('movies.json', encoding='utf-8'))['movies']
# print(movies)
ratings = []
durations = []
for m in movies:
ratings.append(m['rating'])
durations.append(m['duration'])
plt.figure(figsize=(8,5))
plt.hist(ratings, bins=5,color='blue')
plt.savefig('q4_3a_hist.png',dpi=150)

BIN
q4/q4_3a/q4_3a_hist.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

105
q4/q4_3b/movies.json Normal file
View File

@@ -0,0 +1,105 @@
{
"ID": "B-20260625-3464",
"movies": [
{
"id": 1,
"title": "霸王别姬",
"director": "Frank Darabont",
"year": 2004,
"rating": 6.8,
"duration": 179,
"genre": "科幻",
"actors_count": 3
},
{
"id": 2,
"title": "放牛班的春天",
"director": "陈凯歌",
"year": 2019,
"rating": 6.7,
"duration": 117,
"genre": "喜剧",
"actors_count": 5
},
{
"id": 3,
"title": "泰坦尼克号",
"director": "Robert Zemeckis",
"year": 2015,
"rating": 9.1,
"duration": 177,
"genre": "爱情",
"actors_count": 4
},
{
"id": 4,
"title": "三傻大闹宝莱坞",
"director": "James Cameron",
"year": 2024,
"rating": 7.6,
"duration": 117,
"genre": "冒险",
"actors_count": 5
},
{
"id": 5,
"title": "阿甘正传",
"director": "宫崎骏",
"year": 2016,
"rating": 8.0,
"duration": 146,
"genre": "喜剧",
"actors_count": 3
},
{
"id": 6,
"title": "星际穿越",
"director": "Christopher Nolan",
"year": 2010,
"rating": 9.2,
"duration": 168,
"genre": "爱情",
"actors_count": 2
},
{
"id": 7,
"title": "忠犬八公的故事",
"director": "Lasse Hallström",
"year": 2016,
"rating": 9.3,
"duration": 106,
"genre": "悬疑",
"actors_count": 5
},
{
"id": 8,
"title": "肖申克的救赎",
"director": "Rajkumar Hirani",
"year": 2018,
"rating": 7.3,
"duration": 107,
"genre": "剧情",
"actors_count": 4
},
{
"id": 9,
"title": "千与千寻",
"director": "Christophe Barratier",
"year": 2019,
"rating": 7.3,
"duration": 118,
"genre": "动画",
"actors_count": 4
},
{
"id": 10,
"title": "盗梦空间",
"director": "Christopher Nolan",
"year": 2008,
"rating": 9.3,
"duration": 111,
"genre": "动画",
"actors_count": 5
}
]
}

14
q4/q4_3b/q4_3b.py Normal file
View File

@@ -0,0 +1,14 @@
import json
import matplotlib.pyplot as plt
movies = json.load(open('movies.json', encoding='utf-8'))['movies']
# print(movies)
ratings = []
durations = []
for m in movies:
ratings.append(m['rating'])
durations.append(m['duration'])
plt.figure(figsize=(8,5))
plt.hist(durations, bins=5,color='blue')
plt.savefig('q4_3b_hist.png',dpi=150)

BIN
q4/q4_3b/q4_3b_hist.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB