Skip to content

Instantly share code, notes, and snippets.

@wmcraver
Last active September 28, 2016 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmcraver/652bf4132680ce6a35e914ec3b7a13d3 to your computer and use it in GitHub Desktop.
Save wmcraver/652bf4132680ce6a35e914ec3b7a13d3 to your computer and use it in GitHub Desktop.
library(httr)
library(stringr)
dat = read.csv("fileWithURLs.csv", stringsAsFactors = F)
---------------- for loop to get results ----------------
for (i in 1:nrow(dat)) {
a = GET(dat$Current.Forward[i])
dat$URL[i] = a$url
dat$StatusCode[i] = status_code(a)
}
---------------- wrote a function to do this ----------------
urlGetter = function(URL) {
a = GET(URL)
print(a$url)
print(status_code(a))
data.frame("STATUS" = status_code(a),"URL" = a$url)
}
x = sapply(dat$URLlist,urlGetter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment