上传文件至 /
This commit is contained in:
32
douban.py
Normal file
32
douban.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user