This commit is contained in:
2505140092
2026-04-02 16:04:03 +08:00
parent 3102027d04
commit a4318a04a8
8 changed files with 65 additions and 0 deletions

29
dxq.py Normal file
View File

@@ -0,0 +1,29 @@
import requests
from bs4 import BeautifulSoup
url = f"https://movie.douban.com/top250"
headers = {
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
}
print('开始爬取豆瓣电影Top250...')
response = requests.get(url, headers=headers)
print(f'状态码: {response.status_code}')
print(f'内容长度: {len(response.text)} 字符')
# 找到所有电影标题
html = response.text
# 匹配 <span class="title">电影名</span>
title_pattern = r'<span class="title">([^<]+)</span>'
titles = re.findall(title_pattern, html)
# 过滤掉英文名(以/开头)
chinese_titles = [t for t in titles if not t.startswith('/')]
print('电影名称前10部')
for i, title in enumerate(chinese_titles[:10], 1):
print(f'{i}. {title}')