【问题标题】:scraping all the reviews of a IMDB movie in R在 R 中抓取 IMDB 电影的所有评论
【发布时间】:2022-08-14 02:36:20
【问题描述】:

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

但它会抓取已经加载到页面的信息。 (例:如果有 1000 条评论,网页只显示前 10 条评论,其他评论会在点击“加载更多”后显示)

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()

有没有办法抓取每条评论的信息?

    标签: r web-scraping rvest


    【解决方案1】:

    这类似于上一个问题 (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?&amp;paginationKey="+pagination_key

    其中pagination_key 是隐藏在 html 下的数据键: &lt;div class="load-more-data" data-key="g4xolermtiqhejcxxxgs753i36t52q343andv6xeade6qp6qwx57ziim2edmxvqz2tftug54" data-ajaxurl="/title/tt0167260/reviews/_ajax"&gt;

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

    要访问第三页,您需要重复该过程,即从第二页中查找分页键并重复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 2019-10-09
      • 1970-01-01
      • 2022-01-18
      • 2011-06-03
      • 1970-01-01
      • 2014-10-03
      相关资源
      最近更新 更多