上传文件至 /
This commit is contained in:
29
260402 09.py
Normal file
29
260402 09.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
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','Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,,image/webp,image/apng,*/*;q=0.8'}
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
response.encoding = 'utf-8'
|
||||||
|
html = response.text
|
||||||
|
|
||||||
|
title_pattern = r'<span class="title">([^<]+)</span>'
|
||||||
|
titles = re.findall(title_pattern, html)
|
||||||
|
chinese_titles = []
|
||||||
|
for title in titles:
|
||||||
|
if title.strip() and not title.startswith('/'):
|
||||||
|
chinese_titles.append(title)
|
||||||
|
|
||||||
|
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('-' * 45)
|
||||||
|
for i in range(10):
|
||||||
|
try:
|
||||||
|
print(f"{i+1:<4}{chinese_titles[i]:<25}{ratings[i]:<8}{quotes[i]}")
|
||||||
|
except IndexError:
|
||||||
|
print(f"{i+1:<4}数据缺失...")
|
||||||
Reference in New Issue
Block a user