Last active
March 31, 2020 13:34
-
-
Save ryanscharf/bf2eaed83c0ea38894dc2d2ee56c751f to your computer and use it in GitHub Desktop.
getBeanies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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