diff --git a/movies.html b/movies.html
new file mode 100644
index 0000000..e545c70
--- /dev/null
+++ b/movies.html
@@ -0,0 +1,152 @@
+
+
+
+
+
+
+
+ 电影列表
+
+
+
+ 电影列表
+ 数据编号:B-20260623-4783
+
+
+
+
+ | 编号 |
+ 电影名 |
+ 导演 |
+ 上映年份 |
+ 评分 |
+ 时长(分钟) |
+ 类型 |
+ 主演数 |
+
+
+
+
+
+ | 1 |
+ 千与千寻 |
+ Frank Darabont |
+ 2001 |
+ 8.4 |
+ 91 |
+ 悬疑 |
+ 2 |
+
+
+
+ | 2 |
+ 霸王别姬 |
+ 陈凯歌 |
+ 2002 |
+ 9.3 |
+ 125 |
+ 悬疑 |
+ 2 |
+
+
+
+ | 3 |
+ 阿甘正传 |
+ Robert Zemeckis |
+ 1999 |
+ 9.3 |
+ 99 |
+ 喜剧 |
+ 4 |
+
+
+
+ | 4 |
+ 放牛班的春天 |
+ James Cameron |
+ 2012 |
+ 6.3 |
+ 100 |
+ 爱情 |
+ 3 |
+
+
+
+ | 5 |
+ 星际穿越 |
+ 宫崎骏 |
+ 2024 |
+ 6.5 |
+ 166 |
+ 爱情 |
+ 3 |
+
+
+
+ | 6 |
+ 泰坦尼克号 |
+ Christopher Nolan |
+ 2003 |
+ 7.3 |
+ 127 |
+ 动画 |
+ 5 |
+
+
+
+ | 7 |
+ 盗梦空间 |
+ Lasse Hallström |
+ 1993 |
+ 9.2 |
+ 118 |
+ 喜剧 |
+ 4 |
+
+
+
+ | 8 |
+ 忠犬八公的故事 |
+ Rajkumar Hirani |
+ 2003 |
+ 8.9 |
+ 118 |
+ 动画 |
+ 4 |
+
+
+
+ | 9 |
+ 三傻大闹宝莱坞 |
+ Christophe Barratier |
+ 2010 |
+ 8.3 |
+ 137 |
+ 动画 |
+ 2 |
+
+
+
+ | 10 |
+ 肖申克的救赎 |
+ Christopher Nolan |
+ 1999 |
+ 8.2 |
+ 178 |
+ 爱情 |
+ 2 |
+
+
+
+
+
+
\ No newline at end of file
diff --git a/movies.json b/movies.json
new file mode 100644
index 0000000..dc3cb9c
--- /dev/null
+++ b/movies.json
@@ -0,0 +1,105 @@
+{
+ "data_id": null,
+ "movies": [
+ {
+ "id": 1,
+ "title": "千与千寻",
+ "director": "Frank Darabont",
+ "year": 2001,
+ "rating": 8.4,
+ "duration": 91,
+ "genre": "悬疑",
+ "actors_count": 2
+ },
+ {
+ "id": 2,
+ "title": "霸王别姬",
+ "director": "陈凯歌",
+ "year": 2002,
+ "rating": 9.3,
+ "duration": 125,
+ "genre": "悬疑",
+ "actors_count": 2
+ },
+ {
+ "id": 3,
+ "title": "阿甘正传",
+ "director": "Robert Zemeckis",
+ "year": 1999,
+ "rating": 9.3,
+ "duration": 99,
+ "genre": "喜剧",
+ "actors_count": 4
+ },
+ {
+ "id": 4,
+ "title": "放牛班的春天",
+ "director": "James Cameron",
+ "year": 2012,
+ "rating": 6.3,
+ "duration": 100,
+ "genre": "爱情",
+ "actors_count": 3
+ },
+ {
+ "id": 5,
+ "title": "星际穿越",
+ "director": "宫崎骏",
+ "year": 2024,
+ "rating": 6.5,
+ "duration": 166,
+ "genre": "爱情",
+ "actors_count": 3
+ },
+ {
+ "id": 6,
+ "title": "泰坦尼克号",
+ "director": "Christopher Nolan",
+ "year": 2003,
+ "rating": 7.3,
+ "duration": 127,
+ "genre": "动画",
+ "actors_count": 5
+ },
+ {
+ "id": 7,
+ "title": "盗梦空间",
+ "director": "Lasse Hallström",
+ "year": 1993,
+ "rating": 9.2,
+ "duration": 118,
+ "genre": "喜剧",
+ "actors_count": 4
+ },
+ {
+ "id": 8,
+ "title": "忠犬八公的故事",
+ "director": "Rajkumar Hirani",
+ "year": 2003,
+ "rating": 8.9,
+ "duration": 118,
+ "genre": "动画",
+ "actors_count": 4
+ },
+ {
+ "id": 9,
+ "title": "三傻大闹宝莱坞",
+ "director": "Christophe Barratier",
+ "year": 2010,
+ "rating": 8.3,
+ "duration": 137,
+ "genre": "动画",
+ "actors_count": 2
+ },
+ {
+ "id": 10,
+ "title": "肖申克的救赎",
+ "director": "Christopher Nolan",
+ "year": 1999,
+ "rating": 8.2,
+ "duration": 178,
+ "genre": "爱情",
+ "actors_count": 2
+ }
+ ]
+}
\ No newline at end of file
diff --git a/爬虫.py b/爬虫.py
new file mode 100644
index 0000000..20d4f6d
--- /dev/null
+++ b/爬虫.py
@@ -0,0 +1,92 @@
+import requests
+import json
+from bs4 import BeautifulSoup
+
+# 题目强制要求请求头
+url = "https://exam.detr.top/exam-b/movies"
+headers = {
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
+}
+
+# 仅一次请求,符合题目要求
+resp = requests.get(url, headers=headers)
+resp.encoding = "utf-8"
+html_text = resp.text
+
+# 保存原始网页 movies.html
+with open("movies.html", "w", encoding="utf-8") as f:
+ f.write(html_text)
+print("✅ 已保存网页源码 movies.html")
+
+# 解析表格页面
+soup = BeautifulSoup(html_text, "html.parser")
+
+# 提取页面data_id(页面顶部/body标签,没有则留空)
+data_id = None
+if soup.body and "data-id" in soup.body.attrs:
+ data_id = soup.body["data-id"]
+print(f"页面data_id: {data_id}")
+
+# 提取表格所有数据行 ,跳过表头第一行
+all_tr = soup.find_all("tr")
+movie_list = []
+# 表头是第0行,电影从第1行开始遍历
+for tr in all_tr[1:]:
+ td_list = tr.find_all("td")
+ # 表格列顺序:id、title、director、year、rating、duration、genre、actors_count
+ if len(td_list) >= 8:
+ movie = {
+ "id": int(td_list[0].get_text(strip=True)),
+ "title": td_list[1].get_text(strip=True),
+ "director": td_list[2].get_text(strip=True),
+ "year": int(td_list[3].get_text(strip=True)),
+ "rating": float(td_list[4].get_text(strip=True)),
+ "duration": int(td_list[5].get_text(strip=True)),
+ "genre": td_list[6].get_text(strip=True),
+ "actors_count": int(td_list[7].get_text(strip=True))
+ }
+ movie_list.append(movie)
+
+print(f"一共抓取到 {len(movie_list)} 部电影")
+
+# 组装并保存 movies.json
+save_data = {
+ "data_id": data_id,
+ "movies": movie_list
+}
+with open("movies.json", "w", encoding="utf-8") as f:
+ json.dump(save_data, f, ensure_ascii=False, indent=2)
+print("✅ movies.json 写入完成")
+
+# ====================== 第2题数据分析(防止空列表报错) ======================
+if len(movie_list) == 0:
+ print("❌ 未抓取到任何电影数据,请检查表格解析逻辑!")
+else:
+ # ① 找出评分最高、最低电影
+ sorted_movies = sorted(movie_list, key=lambda x: x["rating"])
+ lowest_movie = sorted_movies[0]
+ highest_movie = sorted_movies[-1]
+ print("\n① 评分最高&最低电影:")
+ print(f"评分最低:{lowest_movie['title']} {lowest_movie['rating']}")
+ print(f"评分最高:{highest_movie['title']} {highest_movie['rating']}")
+
+ # ② 统计各类型电影数量(字典输出)
+ genre_count = {}
+ for m in movie_list:
+ g = m["genre"]
+ genre_count[g] = genre_count.get(g, 0) + 1
+ print("\n② 各类型电影数量:", genre_count)
+
+ # ③ 统计各导演电影数量(字典输出)
+ director_count = {}
+ for m in movie_list:
+ d = m["director"]
+ director_count[d] = director_count.get(d, 0) + 1
+ print("\n③ 各导演电影数量:", director_count)
+
+ # ④ 统计2020年(含)以后上映电影
+ count_2020 = 0
+ for m in movie_list:
+ if m["year"] >= 2020:
+ count_2020 += 1
+ print(f"\n④ 2020年(含)后上映电影总数:{count_2020}")
\ No newline at end of file