From 9bd4dc6e98cc108996398d271f012443c9546b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E5=86=8D=E9=A3=9E?= <2509165044@student.example.com> Date: Thu, 2 Apr 2026 16:03:40 +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 --- 44.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 44.py diff --git a/44.py b/44.py new file mode 100644 index 0000000..e0e4860 --- /dev/null +++ b/44.py @@ -0,0 +1,34 @@ +import requests +from bs4 import BeautifulSoup + +headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' +} + +url = 'https://www.douban.com/doulist/3936288/' + +response = requests.get(url, headers=headers) +response.encoding = 'utf-8' +soup = BeautifulSoup(response.text, 'lxml') +movies = soup.select('.doulist-item') # 提取电影条目 + +count = 0 +for movie in movies: + title_link = movie.select_one('a[href^="/subject/"]') + rating = movie.select_one('.rating_nums') + intro = movie.select_one('.abstract') + + if title_link: + title = title_link.get_text(strip=True) + rating_text = rating.text.strip() if rating else '无评分' + intro_text = intro.get_text(strip=True) if intro else '暂无简介' + + print(f'{count + 1}. 电影:{title}') + print(f' 评分:{rating_text}') + print(f' 简介:{intro_text}') + print('-' * 60) + + count += 1 + + if count >= 10: + break \ No newline at end of file