Files
task-2-3-File-Operations/import requests.py
2509165048 acf7901453 2-3
2026-03-31 11:38:33 +08:00

17 lines
542 B
Python

import requests
import re
import csv
import json
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}
url='https://movie.douban.com/top250'
response=requests.get(url,headers=headers)
html=response.text
print('开始爬取豆瓣电影Top250...')
response = requests.get(url, headers=headers)
print(f'状态码: {response.status_code}')
print(f'内容长度: {len(response.text)} 字符')
html = response.text
title_pattern = r'<span class="title">([^<]+)</span>'
titles = re.findall(title_pattern, html)