I want to combine several cells from multiple functions into one data frame.
However, one function return with NULL
result thus I can't combine all of them into one data frame. Anyway, I already have another existing data frame which will be updated (rbind
) with this new data frame.
library(rvest)
url <- "https://webscraper.io/test-sites/e-commerce/allinone/product/233"
doc <- read_html(url)
web <- function(node) {
doc %>%
html_nodes(node) %>%
html_text() %>%
gsub("\n", "", .) %>%
trimws()}
web_na <- possibly(web, otherwise = 0)
web1 <- web_na("h1")
web2 <- web_na(".price")
web3 <- web_na(".just-random-nodes")
df_web <- data.frame(web1, web2, web3)
==========
Result:
Error in data.frame(web1, web2, web3) : arguments imply differing number of rows: 1, 0
Expected Result:
web1 web2 web3
<fctr> <fctr> <fctr>
Test Sites $520.99 0 or NA
How can I adjust my code to combine them?