From b7ed3dd9ec56d4f28050cc7ad41349650c3d1caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E8=B4=B5=E7=8F=8D?= <2509165009@student.example.com> Date: Thu, 2 Apr 2026 16:05: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 09.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 260402 09.py diff --git a/260402 09.py b/260402 09.py new file mode 100644 index 0000000..a9245d1 --- /dev/null +++ b/260402 09.py @@ -0,0 +1,29 @@ +import requests +import re + +url = 'https://www.douban.com/doulist/3936288/' +headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36','Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,,image/webp,image/apng,*/*;q=0.8'} +response = requests.get(url, headers=headers) +response.encoding = 'utf-8' +html = response.text + +title_pattern = r'([^<]+)' +titles = re.findall(title_pattern, html) +chinese_titles = [] +for title in titles: + if title.strip() and not title.startswith('/'): + chinese_titles.append(title) + +rating_pattern = r']*>(\d+\.\d)' +ratings = re.findall(rating_pattern, html) + +quote_pattern = r'([^<]+)' +quotes = re.findall(quote_pattern, html) + +print(f'{"排名":<4} {"电影名":<20} {"评分":<6} {"引言"}') +print('-' * 45) +for i in range(10): + try: + print(f"{i+1:<4}{chinese_titles[i]:<25}{ratings[i]:<8}{quotes[i]}") + except IndexError: + print(f"{i+1:<4}数据缺失...") \ No newline at end of file