I have a df
of unique ids x urls
.
library (httr)
for (i in (1:nrow(df))) {
resp <- httr::GET(df$url[i])
httpcode[i] <- status_code(resp)
httpstatus[i] <- http_status(resp)$reason
}
I want to (a) find the status_code
for every url, (b) find the http_status
for every url, and (c) spit them out into new columns in the same df
.
Problems: 1. In the code below, when I replace i
by an actual index number (e.g. i = 1), the code works. When I put it in a for loop, it gives me the following error:
Error in curl::curl_fetch_memory(url, handle = handle) :
Couldn't resolve host name
- How do I make
httpcode
andhttpstatus
convert from objects into new columns in the samedf
? Thanks