Skip to content

Instantly share code, notes, and snippets.

@andreasio
Last active December 13, 2015 13:00
Show Gist options
  • Save andreasio/42633576d6d0daf3e5b5 to your computer and use it in GitHub Desktop.
Save andreasio/42633576d6d0daf3e5b5 to your computer and use it in GitHub Desktop.
library(httr)
# example
cvrnumbers <- c('10112354', '57471719', '82675418')
cvr2name <- function(cvrnumbers, useragent="mit projekt") {
# this gets company data from cvrapi.dk - its important to specify your project in useragent.
# Its easy to get banned if you don't
require(httr)
results <- vector(length=length(cvrnumbers))
for (i in 1:length(cvrnumbers)) {
cvrvalue <- cvrnumbers[i]
url=paste0('http://cvrapi.dk/api?search=', cvrvalue, "&country=dk")
results[i]<- paste(httr::content(httr::GET(url=url, httr::add_headers("user-agent"=useragent)))[2])
}
return(results)
}
cvr2name(cvrnumbers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment