# function to grab NET data
net_ranks <- function(url) {
net_page <- read_html(url)
net_rk <- net_page %>%
html_nodes("table") %>%
.[1] %>%
html_table(fill = TRUE)
net_table <- as.data.frame(net_rk)
net_table <- net_table %>%
mutate(prev_day_result = net_table[,3]) %>%
mutate(date = gsub("[^0-9.-]", "", colnames(net_table[3]))) %>%
mutate(date = str_sub(date, end = -2)) %>%
mutate(record = str_split(WL, "-", simplify = T),
wins = record[,1],
losses = record[,2],
conf_record = str_split(Conf..Record, "-", simplify = T),
wins_conf = conf_record[,1],
losses_conf = conf_record[,2],
non_conf_record = str_split(Non.Conference.Record, "-", simplify = T),
wins_non_conf = non_conf_record[,1],
losses_non_conf = non_conf_record[,2],
first_q = str_split(Quadrant.1, "-", simplify = T),
q1_win = first_q[,1],
q1_loss = first_q[,2],
second_q = str_split(Quadrant.2, "-", simplify = T),
q2_win = second_q[,1],
q2_loss = second_q[,2],
third_q = str_split(Quadrant.3, "-", simplify = T),
q3_win = third_q[,1],
q3_loss = third_q[,2],
fourth_q = str_split(Quadrant.4, "-", simplify = T),
q4_win = fourth_q[,1],
q4_loss = fourth_q[,2],
) %>%
rename(team = Team, conf = Conference, net = NET, prev_net = Prev.NET,
sos = NET.SOS, non_conf_sos = NET.NonConf.SOS) %>%
select(team, conf, net, prev_net, prev_day_result, sos, non_conf_sos, wins,
losses, wins_non_conf, losses_non_conf, q1_win, q1_loss,
q2_win, q2_loss, q3_win, q3_loss, q4_win, q4_loss, date) %>%
mutate_at(vars(-team, -conf, -date, -prev_day_resu), as.numeric)
}
# function to loop through and grab all data
# net_nums <- function(id) {
# net_ranks(url = id)
# }
# ids <- read_csv("ids.csv)
# ids <- ids$urls
# function to get ACC games
# all_net_rks <- lapply(ids, net_nums)
# load csv of scraped ids
# full_net <- as.data.frame(do.call(rbind, all_net_rks))
# load just the acc teams
lun_acc <- read_csv("acc_teams.csv")