完成作业6

This commit is contained in:
2509165007
2026-04-02 15:56:19 +08:00
parent 3e113f048f
commit b7fe0b3ee4

13
07.py Normal file
View File

@@ -0,0 +1,13 @@
import requests
import re
url = 'https:www.douban.com/doulist/2926288/'
headers = {'User-Agent':'Mozilla/5.0(Windows NT 10.0; Win64; x64)AppleWebKit/537.36'}
response = requests.get(url,headers=headers)
html = response.text
title_pattern = r'<span class="title">([^<]+)</span>'
title = re.findall(title_pattern, html)
Chinese_title = [t for t in title if not t.starswith('/')]
print('电影名称前10部)')
for i,title in enumerate(chinese_titles[:10],1):
print(f'{i}.{title}')