上传文件至 /

This commit is contained in:
2026-03-31 11:27:49 +08:00
parent e9f2512691
commit 70098c7c83

18
26wyc.py Normal file
View File

@@ -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'<span class"title">(.*?)</span>'
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已保存")