Created
January 30, 2016 12:18
-
-
Save harveyl888/23662422ebc6dbeeac76 to your computer and use it in GitHub Desktop.
Scrape lists of breweries and beers from Craft Beer Cellar
This file contains 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
## | |
## 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