0

I want to web scrape some data from a web page daily. I need to save it on a Google sheet. Then I need to update this data set daily (by running the Web scraping code) and update the same Google sheet with new data, replacing the old data. I do not want to create a new Google sheets during the updating process.

This is the data frame that I need to save in the Google Sheet.

# creating a data frame including all the information insert rooms, surface, cost and address
df_two <- cbind.data.frame(flat_cl_one$apt_link,flat_cl_one$rooms, flat_rm, flat_cl_one$surface,
                           flat_sf, flat_cl_one$cost, flat_ct, address, flat_ad)
colnames(df_two) <- c("apt_link", "rooms", "rooms clean", "Surface", "surface clean", 
                      "cost", "cost clean", "address", "address district" )

This is how I save this data frame as a CSV file in "my documents" folder in the computer.

# Saving
con <- file('Real_Estate_Wien_Data.csv',encoding="UTF-8")
write.csv(df_two, file=con, row.names = T)

This is how I tried to upload this data to the drive

# Write Google sheets
library(googlesheets4)
library(googledrive)
drive_auth()
1
# Link to the folder
tf <- drive_get("~/Real_Estate_Wien_Data.csv")
# Update
drive_put('Real_Estate_Wien_Data.csv', name = "Real_Estate_Wien_Data", type="spreadsheet", path=as_id(td)) # keeps id because of other links

But I keep getting this error

Error: Parent specified via path is invalid: x Is neither a folder nor a shared drive. Run rlang::last_error() to see where the error occurred.

Thank You in advance for having a look at this and recommending me a solution?

Dave2e
  • 22,192
  • 18
  • 42
  • 50
  • Please edit your question and include [example]. i don't seen how this code could result in that error message there is nothing in your code about parents. – Linda Lawton - DaImTo Mar 15 '22 at 11:02
  • First, I saved the CSV file on the computer and assigned the path to a variable called "tf”. It didn't work. Then I saved the CSV file in my Google Drive and assigned the link to that CSV file to a variable called "td" and passed it to the "drive_put" function. But still I get the following error.`# Link to the folder tf <- drive_get("~/Real_Estate_Wien_Data.csv") td <- drive_get("drive.google.com/file/d/1rtCjnh3QxeCv4g6DGdgSRo9RVw2EgBUU/…) # Update drive_put('Real_Estate_Wien_Data.csv', name = "Real_Estate_Wien_Data”, type="spreadsheet", path=as_id(tf))` – manoj rasika Mar 16 '22 at 07:12

1 Answers1

0

I figured out the problem. I got this error because I didn't create a separate folder in my Google Drive to put the data. I assigned the URL to "td" the newly created folder in my Google Drive. Then assign that variable to the "path" in the function "drive_put". It worked perfectly.