Próbuję scrapa IMDB.
Utknąłem z następującą rzeczą: zdarzył się brak danych (dokładnie czasu runtime_data) i w związku z tym wywala błąd
"Error in data.frame(Rank = rank_data, Title = title_data, Release.Year = year, :
arguments imply differing number of rows: 250, 249".

Jak obsłużyć przy scrapowaniu brak html_nodes, który jest czytany? Próbowałem IFa z length, ale nie zadziałał. Znacie jakiś psrytny sposób by to obsłuży?

#install packages
install.packages("rvest")
library(rvest)

#create empty frame
filmy_df=data.frame()

#empty values
rank_data<-NA;link<-NA;year<-NA;title_data<-NA;description_data<-NA;runtime_data<-NA;genre_data<-NA

#set link for browser
newURL<-"https://www.imdb.com/search/title/?title_type=feature&release_date=,2018-12-31&count=250&start=2751"

#read webpage code
strona_int<-read_html(newURL)

#read rank
rank_data<-html_nodes(strona_int,'.text-primary')
#convert text
rank_data<-html_text(rank_data)
#remove the comma for thousands
rank_data<-gsub(",","",rank_data)
#convert numeric
rank_data<-as.numeric(rank_data)

#read link for each movie
link<-url_absolute(html_nodes(strona_int, '.lister-item-header a')%>%html_attr(.,'href'),"https://www.imdb.com")

#release year
year<-html_nodes(strona_int,'.lister-item-year')
#convert text
year<-html_text(year)
#remove non numeric
year<-gsub("\\D","",year)
#set factor
year<-as.factor(year)

#read title
title_data<-html_nodes(strona_int,'.lister-item-header a')
#convert text
title_data<-html_text(title_data)
#title_data<-as.character(title_data)

#read description
description_data<-html_nodes(strona_int,'.ratings-bar+ .text-muted')
#convert text
description_data<-html_text(description_data)
#remove '\n'
description_data<-gsub("\n","",description_data)
#remove space
description_data<-trimws(description_data,"l")

#read runtime
runtime_data <- html_nodes(strona_int,'.text-muted .runtime')
#convert text
runtime_data <- html_text(runtime_data)
#remove min
runtime_data<-gsub(" min","",runtime_data)
length_runtime_data<-length(runtime_data)
#if (length_runtime_data<250){ runtime_data<-append(runtime_data,list(0))}
runtime_data<-as.numeric(runtime_data)

czas_emisji<-if (length(html_nodes(strona_int,'.text-muted .runtime'))==0){
  return(NA)
} else {
  czas_emisji<-html_nodes(strona_int,'.text-muted .runtime')
}
czas_emisji <- html_text(czas_emisji)
#remove min
czas_emisji<-gsub(" min","",czas_emisji)
czas_emisji<-as.numeric(czas_emisji)

#temp_df
filmy_df_temp<-data.frame(Rank=rank_data,Title=title_data,Release.Year=year,Link=link,Description=description_data,Runtime=runtime_data)

#add to df
filmy_df<-rbind(filmy_df,filmy_df_temp)

Problem jest dokładnie z filmem "Anima" na pozycji 2766, gdzie brakuje właśnie runtime (w kodzie strony porównując z innymi pozycjami można zauważyć, że html_nodes(strona_int,'.text-muted .runtime') dla tego filmu w ogóle nie jest użyty).