From 60881bbc7eb625921443a5336d48c533950d1cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E4=BC=A0=E6=95=8F?= <2509165031@student.example.com> Date: Thu, 11 Jun 2026 16:35:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pachong.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 pachong.py diff --git a/pachong.py b/pachong.py new file mode 100644 index 0000000..a35c08d --- /dev/null +++ b/pachong.py @@ -0,0 +1,46 @@ +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" +} + + +data = [] +for start in range(0, 250, 25): + url = f"https://movie.douban.com/top250?start={start}&filter=" + resp = requests.get(url, headers=headers) + resp.encoding = "utf-8" + soup = bs(resp.text, "html.parser") + items = soup.find_all("div", class_="item") + + for item in items: + + title = item.find("span", class_="title").get_text() + + + info_text = item.find("div", class_="bd").get_text().strip() + + info_lines = [line.strip() for line in info_text.split("\n") if line.strip()] + actors = "" + for line in info_lines: + if "主演:" in line: + actors = line.split("主演:")[-1].strip() + break + + + quote = "" + quote_tag = item.find("p", class_="quote") + if quote_tag: + quote = quote_tag.get_text().strip() + + 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, indent=4) \ No newline at end of file