From 70098c7c83d5cef2c4e1abed591a23bee106f4cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=AE=87=E6=99=A8?= <2509165026@student.example.com> Date: Tue, 31 Mar 2026 11:27:49 +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 --- 26wyc.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 26wyc.py diff --git a/26wyc.py b/26wyc.py new file mode 100644 index 0000000..b74a76b --- /dev/null +++ b/26wyc.py @@ -0,0 +1,18 @@ +import requests +import re +url = 'https://movie.douban.com/top250' +headers = { + 'User-Agent':'Mozilla/5.0(Windows NT 6.1: Win64; x64)AppleWebkit/537.36(KHTML,like Gecko) Chrome/120.0.0.0 Safari/537.36' +} + +response = requests.get(url,headers=headers) +response.encoding = 'utf-8' +html = response.text +pattern = r'(.*?)' +titles = re.findall(pattern,html) +chinese_titles = [titles for title in titles if "/" not in title ] +top10_titles = chinese_titles[:10] +with open ("movies.txt","w",encoding="utf-8") as f: + for idx, titles in enumerate(top10_titles, 1): + f.write(f"{idx}.{titles}\n") + print("movies.txt已保存") \ No newline at end of file