刮掉一部IMDB电影的所有评论刮掉、电影、IMDB

2023-09-03 14:31:53 作者:-如果时光她寂寞

我编写了取消电影评论和详细评论的代码。

但它会丢弃已加载到页面的信息。(例如:如果有1000条评论,网页将只显示前10条评论。其他评论将在单击&q;加载更多&q;后显示。)

require(rvest)
require(dplyr)    
MOVIE_URL <- read_html("https://www.imdb.com/title/tt0167260/reviews?ref_=tt_urv")
    ex_review <- MOVIE_URL %>% html_nodes(".lister-item a") %>%
      html_text()
    detialed <-  MOVIE_URL %>% html_nodes(".content")%>%
      html_text()
IMDb评选 电影人必看的10部短片 附视频

有没有办法收集每一篇评论的信息?

推荐答案

这与上一个问题(How to scrape all the movie reviews from IMDB using rvest)类似,但答案不再起作用。

现在,当您查看单个评论页面(https://www.imdb.com/title/tt0167260/reviews)时,您可以通过url:

加载下一页评论评论

movieurl = "https://www.imdb.com/title/tt0167260/reviews/_ajax?&paginationKey="+pagination_key

其中pagination_key是隐藏在html中的data-key,位于: <div class="load-more-data" data-key="g4xolermtiqhejcxxxgs753i36t52q343andv6xeade6qp6qwx57ziim2edmxvqz2tftug54" data-ajaxurl="/title/tt0167260/reviews/_ajax">

因此,如果您从movie_url = "https://www.imdb.com/title/tt0167260/reviews/_ajax?&paginationKey=g4xolermtiqhejcxxxgs753i36t52q343andv6xeade6qp6qwx57ziim2edmxvqz2tftug54"检索html,您将获得第二页评论。

若要访问第三个页面,您需要重复该过程,即从第二个页面中查找分页密钥并重复。