From 603ac75e9367fada74c0b2c15a0d163ab59640d2 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: Tue, 31 Mar 2026 11:29:56 +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 --- 260331 2505155046.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 260331 2505155046.py diff --git a/260331 2505155046.py b/260331 2505155046.py new file mode 100644 index 0000000..7916f27 --- /dev/null +++ b/260331 2505155046.py @@ -0,0 +1,19 @@ +import requests +import re + +url = 'https://movie.douban.com/top250' +headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' +} +response = requests.get(url, headers=headers) +html = response.text +pattern = r'([^<&]+)' +titles = re.findall(pattern, html) +chinese_titles = [t for t in titles if not t.startswith('/')] +top10 = chinese_titles[:10] +with open('movies.txt', 'w', encoding='utf-8') as f: + for i, title in enumerate(top10, 1): + f.write(f'{i}. {title}\n') +print('已保存前10部电影到 movies.txt') +with open('movies.txt', 'r', encoding='utf-8') as f: + print(f.read()) \ No newline at end of file