We are a dream team!
library(tidyr) library(rvest) library(tibble) key <- "key=7fdd14996c2133c74184f71e087ddf19" base_url <- "http://api.petfinder.com/" method <- "pet.find" query <- "animal=dog&location=50010" url <- sprintf("%s%s?%s&%s", base_url, method, key, query) ames_dogs <- read_xml(url) %>% xml_nodes("pet") dog_to_df <- function(x) { tibble( name = xml_node(x, "name") %>% xml_text(), breed = xml_nodes(x, "breed") %>% xml_text() %>% paste(collapse = ", "), age = xml_node(x, "age") %>% xml_text(), sex = xml_node(x, "sex") %>% xml_text(), id = xml_node(x, "id") %>% xml_text(), shelterID = xml_node(x, "shelterId") %>% xml_text(), location = xml_node(x, "location") %>% xml_text(), pics = list(xml_nodes(x, "photo") %>% xml_text()), ) } ames_dog_df <- ames_dogs %>% purrr::map_df(dog_to_df)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.