dbo
dbo

Reputation: 1234

scraping all tables from a single webpage?

For the first site the data is scraped into the reservoirs data.frame that just needs some tidying, but for the second there's two sets of tables, an upper and lower, and I don't know how to get the lower.

sites:

1) http://cdec.water.ca.gov/reportapp/javareports?name=RES

2) http://cdec.water.ca.gov/reportapp/javareports?name=FNF

library(tidyverse)
library(XML)

reservoirs <-  "http://cdec.water.ca.gov/reportapp/javareports?name=RES" %>% 
               readHTMLTable() %>% 
               data.frame()  

flows_part1 <- "http://cdec.water.ca.gov/reportapp/javareports?name=FNF" %>% 
               readHTMLTable() %>% 
               data.frame()


#flows_part2 <- ??  

Any ideas on how to get the second table from the second site (or a better way to get everything initially?)

Thank you!

Upvotes: 0

Views: 38

Answers (1)

Matt Jewett
Matt Jewett

Reputation: 3369

The readHTMLTable function will store all of the tables into a list which can then be extracted from each list element.

flows <-  readHTMLTable("http://cdec.water.ca.gov/reportapp/javareports?name=FNF", as.data.frame = TRUE)

flows_part1 <- flows[[1]]
flows_part2 <- flows[[2]]

Upvotes: 1

Related Questions