'Using R code to scrape data from a webpage into an Excel file

I have written a code in R which is supposed to retrieve certain information from a website and import it into an Excel file. I have used it for one website and it works, but for this particular website, it has an issue, it returns N/A values in excel, and I don't know why.

library(tidyverse) 
library(rvest)
library(string)
library(rebus)
library(lubridate)
library(xlsx)
library(reader)

setwd("C:/Users/user/Desktop/Tenders")
getwd()

ran=seq(300100,300000,-1)
result = data.frame(matrix(nrow = length(ran), ncol = 1))
colnames(result) <- c("111")


for (i in ran){
    url <- paste0("http://tenders.procurement.gov.ge/public/?go=", i)
    
    download.file(url, destfile = "scrapedpage.html", quiet=TRUE)
    content <- read_html("scrapedpage.html")
    
    
    #111
    status=content %>% html_nodes("#print_area tr:nth-child(1) td + td")%>% html_text()
    status[length(status) == 0] <- NA
    status=as.data.frame(status)
    status=(if (nrow(status)>1){
      a=as.matrix(paste(unlist(status), collapse =" "))
    } else {as.matrix(status)
      
    })
    result[i, 1]=status
}

s=as.data.frame(ran)
final=result[-c(1:s[nrow(s),]),]
#Excel
write.xlsx(final,"C:/Users/user/Desktop/Tenders.xlsx", sheetName = "111")

I am using selector gadget tool, which is a chrome extension for identifying HTML parts that the code is supposed to use to gather the information (for example, in the code above it is "#print_area tr:nth-child(1) td + td", which is the first entry in the link).

Can someone help me find out what the issue might be?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source