url <- 'https://www.imdb.com/search/title/?title_type=feature&release_date=2020-01-01,2020-12-31&count=100'
webpage <- read_html(url)

If we get data using html_nodes directly, we will find that there are only 90 metascore, instead of 100.

metascore_data_html <- html_nodes(webpage,'.metascore')
metascore_data <- html_text(metascore_data_html)
metascore_data <-  as.integer(metascore_data)
length(metascore_data)
## [1] 90
metascore_data
##  [1] 43 88 69 73 71 68 71 14 79 55 90 26 93 65 60 47 83 81 66 36 22 69 50 72 83
## [26] 60 48 67 68 43 56 47 75 66 76 80 40 64 70 63 78 66 56 67 56 64 76 46 89 43
## [51] 13 56 59 73 39 47 79 73 79 73 50 61 79 54 67 52 65 49 22 62 66 48 58 33 72
## [76] 62 41 58 51 46 51 44 51 72 61 63 71 51 67 31

According to the rvest help guide, it states that “html_node() returns a nodeset the same length as the input.” So we can first use html_nodes to find a subset which contains 100 matches, then use html_node to find the metascore of this subset. Because html_node will return the same length as the input (which is 100 in this case), html_node will fill the missing value as NA automatically.

For the subset, we can use any element in the webpage that contains the metascore, including but not limited to .mode-advanced, .lister-item-content, .ratings-bar.

metascore_data_html <- html_node(html_nodes(webpage, '.ratings-bar'), '.metascore')
metascore_data <- html_text(metascore_data_html)
metascore_data <-  as.integer(metascore_data)
length(metascore_data)
## [1] 100
metascore_data
##   [1] 43 NA 88 69 73 71 68 71 14 79 55 90 26 93 65 60 47 83 81 66 36 22 69 50 72
##  [26] 83 60 48 67 68 NA 43 56 47 75 66 76 NA 80 40 64 70 63 78 66 56 67 56 64 76
##  [51] 46 89 43 NA 13 56 59 73 39 47 79 73 79 73 50 61 79 54 67 52 65 49 22 62 66
##  [76] NA 48 58 33 72 62 41 58 NA 51 46 51 NA 44 51 72 61 NA 63 71 51 67 NA NA 31

Reference:

https://www.programmerall.com/article/4032974459/

https://rvest.tidyverse.org/reference/html_nodes.html