I am attempting to scrape MLB lineups from the following URL:
https://www.baseballpress.com/lineups/
However, when a lineup is unreleased, the nodes for each individual players do not exist on the page. Therefore a scape like the following will simply skip the game and then the lineups will not match up correctly when I bind the values together.
vbatter1 = page %>% html_nodes(".col--min:nth-child(1) .player:nth-child(1) .player-link") %>% html_attr("data-mlb")
vbatter2 = page %>% html_nodes(".col--min:nth-child(1) .player:nth-child(2) .player-link") %>% html_attr("data-mlb")
...
hbatter1 = page %>% html_nodes(".col--min+ .col--min .player:nth-child(1) .player-link") %>% html_attr("data-mlb")
hbatter2 = page %>% html_nodes(".col--min+ .col--min .player:nth-child(2) .player-link") %>% html_attr("data-mlb")
...
df <- do.call(rbind, Map(data.frame, GameTime=time, VisTm=VisTm, HmTm=HmTm, VisStPchID=vSP, HmStPchID=hSP, VisBat1ID=vbatter1, VisBat2ID=vbatter2, VisBat3ID=vbatter3, VisBat4ID=vbatter4, VisBat5ID=vbatter5, VisBat6ID=vbatter6, VisBat7ID=vbatter7, VisBat8ID=vbatter8, VisBat9ID=vbatter9, HmBat1ID=hbatter1, HmBat2ID=hbatter2, HmBat3ID=hbatter3, HmBat4ID=hbatter4, HmBat5ID=hbatter5, HmBat6ID=hbatter6, HmBat7ID=hbatter7, HmBat8ID=hbatter8, HmBat9ID=hbatter9))
Is there any way to return NULL values for the missing nodes when the lineup card looks like the following?