Files
2026-03-24 11:31:47 +08:00

28 lines
748 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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',
}
for page in range(10):
url =f'https://www.douban.com/doulist/3936288/?start={page*25}&filter='
print(f"正在爬取第{page+1} {url}")
response = response.get(url,headers=headers,timeout=10)
response.encoding = 'utf-8'
#print(response.status_code)
soup = BeautifulSoup(response.text,'html.parser')
movies = []
for a in soup.find_all('a'):
href = a.get('herf','')
if '/subject' in href:
title = a.get_text(strip=True)
print(title)
movies.append(title)
print('---------')
print(movies)