Skip to content

Instantly share code, notes, and snippets.

@ryanscharf
Last active March 31, 2020 13:34
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 ryanscharf/bf2eaed83c0ea38894dc2d2ee56c751f to your computer and use it in GitHub Desktop.
Save ryanscharf/bf2eaed83c0ea38894dc2d2ee56c751f to your computer and use it in GitHub Desktop.
getBeanies
library(rvest)
library(tidyverse)
library(curl)
bbdb <- 'http://world.ty.com/catalog/catPagePrint.cfm'
bbnames <-
read_html(curl(bbdb, handle = curl::new_handle("useragent" = "Mozilla/5.0"))) %>%
html_node('table') %>%
html_table()
bbnames <- bbnames[3:nrow(bbnames), 2]
bbnames <- tolower(bbnames)
bbnames <- gsub("#|\\s|\\'|-|\\(|\\)|\"", '', bbnames)
bburls <- paste0('https://www.bbtoystore.com/mm5/beanies/',bbnames,'.jpg')
bburls_exist <- purrr::map(.x=bburls, .f = httr::url_success)
bbnames_legit <- bbnames[unlist(bburls_exist)]
bburls_legit <- bburls[unlist(bburls_exist)]
purrr::walk2(.x = bburls_legit,
.y = paste0('~/Beanie Babies - my top 500/',bbnames_legit,'.jpg'),
.f=~safely(download.file(.x,.y, mode = 'wb'),otherwise = NA))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment