使用Python抓取RottenTomatoes观众评论可以通过以下步骤实现:
import requests
from bs4 import BeautifulSoup
url = "https://www.rottentomatoes.com/m/movie_name/reviews?type=user"
response = requests.get(url)
html_content = response.text
请注意,将"movie_name"替换为实际电影的名称。
soup = BeautifulSoup(html_content, "html.parser")
reviews = soup.find_all("div", class_="user_review")
for review in reviews:
comment = review.find("div", class_="user_review--base")
print(comment.text)
这将打印出每个观众评论的文本内容。
for page in range(1, num_pages + 1):
url = f"https://www.rottentomatoes.com/m/movie_name/reviews?page={page}&type=user"
response = requests.get(url)
html_content = response.text
soup = BeautifulSoup(html_content, "html.parser")
reviews = soup.find_all("div", class_="user_review")
for review in reviews:
comment = review.find("div", class_="user_review--base")
print(comment.text)
请注意,将"movie_name"替换为实际电影的名称,并将"num_pages"替换为要抓取的页数。
这是使用Python抓取RottenTomatoes观众评论的基本步骤。根据实际需求,你可以进一步处理评论数据,例如保存到文件、进行情感分析等。
领取专属 10元无门槛券
手把手带您无忧上云