Skip to content

Instantly share code, notes, and snippets.

@harveyl888
Created January 30, 2016 12:18
Show Gist options
  • Save harveyl888/23662422ebc6dbeeac76 to your computer and use it in GitHub Desktop.
Save harveyl888/23662422ebc6dbeeac76 to your computer and use it in GitHub Desktop.
Scrape lists of breweries and beers from Craft Beer Cellar
##
## beerList
##
library(xml2)
library(stringr)
##url <- "http://www.craftbeercellar.com/belmont/beers.php?sort=country" ## Belmont location
url <- "http://www.craftbeercellar.com/winchester/beers.php?sort=country" ## Winchester location
html <- read_html(url)
## list of breweries
breweryList <- xml_find_all(html, '//*[contains(@class, "beerListHeading")]')
breweryList <- xml_text(breweryList)
## list of beers
beerList <- xml_find_all(html, '//*[contains(@class, "beerListItem")]')
beerList <- xml_text(beerList)
beerList <- str_trim(beerList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment