From dbf5494f22597218673b229cb2c228bd11ae8aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A9=89=E5=A7=97?= <2509165046@student.example.com> Date: Thu, 2 Apr 2026 15:58:03 +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 --- douban.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 douban.py diff --git a/douban.py b/douban.py new file mode 100644 index 0000000..8f9b811 --- /dev/null +++ b/douban.py @@ -0,0 +1,32 @@ + +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') + + if title_link: + title = title_link.get_text(strip=True) + rating_text = rating.text.strip() if rating else '无评分' + print(f'{count + 1}. {title} - 评分: {rating_text}') + count += 1 + + if count >= 10: + break