上传文件至 /

This commit is contained in:
2026-04-02 16:04:52 +08:00
parent 9bb930706b
commit b34e7d2863

26
26.04.02 43.py Normal file
View File

@@ -0,0 +1,26 @@
import requests
import re
url = 'https://www.douban.com/doulist/3936288/'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'}
response = requests.get(url, headers=headers)
response.encoding = response.apparent_encoding
html = response.text
title_pattern = r'<span class="title">([^<]+)</span>'
titles = re.findall(title_pattern, html)
chinese_titles = [t.strip() for t in titles if not t.startswith('/')]
rating_pattern = r'<span class="rating_num"[^>]*>(\d+\.\d)</span>'
ratings = re.findall(rating_pattern, html)
quote_pattern = r'<span class="inq">([^<]+)</span>'
quotes = re.findall(quote_pattern, html)
print(f"{'排名':<4} {'电影名':<20} {'评分':<6} {'引言'}")
print('-' * 40)
for i in range(min(10, len(chinese_titles))):
title = chinese_titles[i] if i<len(chinese_titles) else ''
rating = ratings[i] if i < len(ratings) else ''
quote = f'"{quotes[i]}"' if i < len(quotes) else ''
print(f"{i+1:<4} {title:<20} {rating:<6} {quote}")