From 12440c70358793d58450239cbfa749781f50c6cf Mon Sep 17 00:00:00 2001 From: 2509165011 <2509165011@student.edu.cn> Date: Tue, 31 Mar 2026 11:30:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BD=9C=E4=B8=9A=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 11yzz.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 11yzz.py diff --git a/11yzz.py b/11yzz.py new file mode 100644 index 0000000..97810a6 --- /dev/null +++ b/11yzz.py @@ -0,0 +1,25 @@ +import requests +import re + +headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' +} +url = 'https://movie.douban.com/top250' + +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())