上传文件至 /

This commit is contained in:
2026-06-11 16:34:20 +08:00
parent 6467805165
commit ebbf1ec896
2 changed files with 69 additions and 0 deletions

68
douban.py Normal file
View File

@@ -0,0 +1,68 @@
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://movie.douban.com/top250?start=0&filter="
data = []
resp = requests.get(url, headers=headers)
resp.encoding = 'utf-8'
soup = bs(resp.text, "html.parser")
# print(soup)
items = soup.find_all("div", class_="item")
# print(items[0])
# print(len(items))
for i in range(len(items)):
print(i)
title = items[i].find("span", class_="title").get_text()
# print(title)
actors = items[i].find("div", class_="bd").get_text().strip()
try:
actors = actors.split("主演:")[1].split("\n")[0].strip()
except:
actors = ""
#print(actors)
quote = items[i].find("div", class_="bd").find("p", class_="quote").get_text().strip()
# print(quote)
data.append({
"title": title,
"actors": actors,
"quote": quote
})
for i in range(len(items)):
# 电影标题
title = items[i].find("span", class_="title").get_text().strip()
# 演员信息
actors = items[i].find("div", class_="bd").get_text().strip()
try:
actors = actors.split("主演:")[1].split("\n")[0].strip()
except:
actors = ""
# 经典台词
try:
quote = items[i].find("div", class_="bd").find("p", class_="quote").get_text().strip()
except:
quote = ""
# print(quote)
data.append({
"title": title,
"actors": actors,
"quote": quote
})
print(data)
with open("movies.json", "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False)

1
movies.json Normal file
View File

@@ -0,0 +1 @@
[{"title": "肖申克的救赎", "actors": "蒂姆·罗宾斯 Tim Robbins /...", "quote": "希望让人自由。"}, {"title": "霸王别姬", "actors": "张国荣 Leslie Cheung / 张丰毅 Fengyi Zha...", "quote": "风华绝代。"}, {"title": "泰坦尼克号", "actors": "莱昂纳多·迪卡普里奥 Leonardo...", "quote": "失去的才是永恒的。"}, {"title": "阿甘正传", "actors": "汤姆·汉克斯 Tom Hanks / ...", "quote": "一部美国近现代史。"}, {"title": "千与千寻", "actors": "柊瑠美 Rumi Hîragi / 入野自由 Miy...", "quote": "最好的宫崎骏,最好的久石让。"}, {"title": "美丽人生", "actors": "罗伯托·贝尼尼 Roberto Beni...", "quote": "最美的谎言。"}, {"title": "星际穿越", "actors": "马修·麦康纳 Matthew Mc...", "quote": "爱是一种力量,让我们超越时空感知它的存在。"}, {"title": "这个杀手不太冷", "actors": "让·雷诺 Jean Reno / 娜塔莉·波特曼 ...", "quote": "怪蜀黍和小萝莉不得不说的故事。"}, {"title": "盗梦空间", "actors": "莱昂纳多·迪卡普里奥 Le...", "quote": "诺兰给了我们一场无法盗取的梦。"}, {"title": "楚门的世界", "actors": "金·凯瑞 Jim Carrey / 劳拉·琳妮 Lau...", "quote": "如果再也不能见到你,祝你早安,午安,晚安。"}, {"title": "辛德勒的名单", "actors": "连姆·尼森 Liam Neeson...", "quote": "拯救一个人,就是拯救整个世界。"}, {"title": "忠犬八公的故事", "actors": "理查·基尔 Richard Ger...", "quote": "永远都不能忘记你所爱的人。"}, {"title": "海上钢琴师", "actors": "蒂姆·罗斯 Tim Roth / ...", "quote": "每个人都要走一条自己坚定了的路,就算是粉身碎骨。"}, {"title": "疯狂动物城", "actors": "金妮弗·...", "quote": "迪士尼给我们营造的乌托邦就是这样,永远善良勇敢,永远出乎意料。"}, {"title": "三傻大闹宝莱坞", "actors": "阿米尔·汗 Aamir Khan / 卡...", "quote": "英俊版憨豆,高情商版谢耳朵。"}, {"title": "机器人总动员", "actors": "本·贝尔特 Ben Burtt / 艾丽...", "quote": "小瓦力,大人生。"}, {"title": "放牛班的春天", "actors": "让-巴蒂斯特·莫尼...", "quote": "天籁一般的童声,是最接近上帝的存在。"}, {"title": "无间道", "actors": "刘德华 Andy Lau / 梁朝伟 Tony Leung Chiu W...", "quote": "香港电影史上永不过时的杰作。"}, {"title": "控方证人", "actors": "泰隆·鲍华 Tyrone Power / 玛琳·...", "quote": "比利·怀德满分作品。"}, {"title": "寻梦环游记", "actors": "...", "quote": "死亡不是真的逝去,遗忘才是永恒的消亡。"}, {"title": "大话西游之大圣娶亲", "actors": "周星驰 Stephen Chow / 吴孟达 Man Tat Ng...", "quote": "一生所爱。"}, {"title": "熔炉", "actors": "孔侑 Yoo Gong / 郑有美 Yu-mi Jung /...", "quote": "我们一路奋战不是为了改变世界,而是为了不让世界改变我们。"}, {"title": "触不可及", "actors": "无", "quote": "满满温情的高雅喜剧。"}, {"title": "教父", "actors": "马龙·白兰度 M...", "quote": "千万不要记恨你的对手,这样会让你失去理智。"}, {"title": "末代皇帝", "actors": "尊龙 John Lone / 陈...", "quote": "“不要跟我比惨,我比你更惨”再适合这部电影不过了。"}, {"title": "末代皇帝", "actors": "尊龙 John Lone / 陈...", "quote": "“不要跟我比惨,我比你更惨”再适合这部电影不过了。"}]