33 lines
837 B
Python
33 lines
837 B
Python
|
|
import requests
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
headers = {
|
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
|
}
|
|
|
|
|
|
url = 'https://www.douban.com/doulist/3936288/'
|
|
|
|
|
|
response = requests.get(url, headers=headers)
|
|
response.encoding = 'utf-8'
|
|
soup = BeautifulSoup(response.text, 'lxml')
|
|
movies = soup.select('.doulist-item') #
|
|
|
|
|
|
count = 0
|
|
for movie in movies:
|
|
title_link = movie.select_one('a[href^="/subject/"]')
|
|
rating = movie.select_one('.rating_nums')
|
|
|
|
if title_link:
|
|
title = title_link.get_text(strip=True)
|
|
rating_text = rating.text.strip() if rating else '无评分'
|
|
print(f'{count + 1}. {title} - 评分: {rating_text}')
|
|
count += 1
|
|
|
|
if count >= 10:
|
|
break
|