https://movie.douban.com/subject/27110363/comments?start=0&limit=20&sort=new_score&status=P&percent_type=h

以下是抓取代码示例:

import requests
from bs4 import BeautifulSoup

url = 'https://movie.douban.com/subject/27110363/comments'
params = {
    'start': 0,
    'limit': 20,
    'sort': 'new_score',
    'status': 'P',
    'percent_type': 'h'
}

while True:
    res = requests.get(url, params=params)
    soup = BeautifulSoup(res.text, 'html.parser')
    
    comments = soup.find_all('span', class_='short')
    for comment in comments:
        print(comment.text.strip())

    next_link = soup.find('link', rel='next')
    if next_link:
        params['start'] += 20
        url = next_link['href']
    else:
        break

该代码使用了requests库进行HTTP请求,使用了BeautifulSoup库进行HTML解析,通过循环抓取豆瓣电影《穿靴子的猫2》的影评数据,并将其输出到控制台。其中,params参数用于控制抓取的起始位置、抓取数量、排序方式等参数,通过循环不断更新起始位置并请求下一页的数据,直到没有下一页为止


原文地址: https://www.cveoy.top/t/topic/g6ZW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录