上传文件至 q2_1_crawler

This commit is contained in:
2026-06-23 11:20:07 +08:00
parent 8e12bbc281
commit 1d1a1b8979
4 changed files with 341 additions and 0 deletions

34
q2_1_crawler/260623.py Normal file
View File

@@ -0,0 +1,34 @@
import json
with open("movies.json", "r", encoding="utf-8") as f:
total_data = json.load(f)
movie_list = total_data["movies"]
# ① 最高分、最低分电影
max_movie = max(movie_list, key=lambda x: x["rating"])
min_movie = min(movie_list, key=lambda x: x["rating"])
print("评分最高电影:", max_movie["title"], ",评分:", max_movie["rating"])
print("评分最低电影:", min_movie["title"], ",评分:", min_movie["rating"])
# ② 统计各电影类型数量
genre_dict = {}
for m in movie_list:
g_list = m["genre"].split(",")
for g in g_list:
g = g.strip()
genre_dict[g] = genre_dict.get(g, 0) + 1
print("\n各类型电影数量:", genre_dict)
# ③ 统计各导演电影数量
director_dict = {}
for m in movie_list:
name = m["director"]
director_dict[name] = director_dict.get(name, 0) + 1
print("\n各导演电影数量:", director_dict)
# ④ 统计2020年后上映影片
cnt = 0
for m in movie_list:
if m["year"] >= 2020:
cnt += 1
print("\n2020年以后上映电影总数", cnt)