Skip to content
Prev 3148 / 7420 Next

Help with function to webscrap

Hai Augusto,

regarding question #3:
You could use the red list API with RCurl and XML packages.
Here is an example:

 > require(RCurl)
 > require(XML)
 > get_IUCN_status <- function(x) {
+   spec <- tolower(x)
+   spec <- gsub(" ", "-", spec)
+   url <- paste("http://api.iucnredlist.org/go/", spec, sep="")
+   get <- getURL(url, followlocation = TRUE)
+   h <- htmlParse(get)
+   status <- xpathSApply(h, '//div[@id ="red_list_category_code"]', 
xmlValue)
+   return(status)
+ }
 >
 > get_IUCN_status("Panthera uncia")
[1] "EN"

For more resources just type 'webscraping R' in your favourite search 
engine.

HTH,

Eduard
On 26/06/12 20:57, Augusto Ribas wrote: