diff --git a/260402 09.py b/260402 09.py new file mode 100644 index 0000000..a9245d1 --- /dev/null +++ b/260402 09.py @@ -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'([^<]+)' +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']*>(\d+\.\d)' +ratings = re.findall(rating_pattern, html) + +quote_pattern = r'([^<]+)' +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}数据缺失...") \ No newline at end of file