From 2bd96675c00541f0bc7ab2bb0b2c6d7fb8ef8d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=85=B4=E5=AE=87?= <2505155046@student.example.com> Date: Thu, 2 Apr 2026 16:04:48 +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 --- 260402 2505155046.py | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 260402 2505155046.py diff --git a/260402 2505155046.py b/260402 2505155046.py new file mode 100644 index 0000000..7d243cb --- /dev/null +++ b/260402 2505155046.py @@ -0,0 +1,48 @@ +import requests +import re +import time + +def crawl_douban_top250_regex_with_quote(): + base_url = "https://movie.douban.com/top250" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" + } + + movies = [] + + for start in range(0, 250, 25): + url = f"{base_url}?start={start}&filter=" + + response = requests.get(url, headers=headers) + html = response.text + + pattern = re.compile( + r'(\d+).+?' + r'([^&]+?).+?' + r'(\d\.\d).+?' + r'

(.+?)

', + re.S + ) + + + items = pattern.findall(html) + + for item in items: + rank = item[0] + title = item[1] + rating = item[2] + quote = item[3].strip() + + movies.append({ + "rank": rank, + "title": title, + "rating": rating, + "quote": quote + }) + + + return movies + +if __name__ == "__main__": + + top250 = crawl_douban_top250_regex_with_quote() \ No newline at end of file