-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_schedule.R
More file actions
31 lines (24 loc) · 1.08 KB
/
Copy pathget_schedule.R
File metadata and controls
31 lines (24 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
get.schedule <- function() {
splashurl <- "http://www.predictthepremiership.com/?lang=en_us"
loginurl <- "https://premierleague.predictthefootball.com/site/login?lang=en_us"
mainurl <- "https://premierleague.predictthefootball.com/profile/index"
ua <- "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322)"
info <- readLines("~/ptp-kshirley.txt")
email <- info[1]
passwd <- info[2]
curl <- getCurlHandle()
curlSetOpt(cookiejar = "", useragent = ua, followlocation = TRUE, curl = curl)
html <- getURL(splashurl, curl = curl)
YII.CSRF.TOKEN <- str_extract( html , "\"[:xdigit:]{40}\"")
YII.CSRF.TOKEN <- substring(YII.CSRF.TOKEN, 2, 41)
pars <- list('YII_CSRF_TOKEN' = YII.CSRF.TOKEN,
'LoginForm[email]' = email,
'LoginForm[password]' = passwd,
'LoginForm[rememberMe]' = '0')
html <- postForm(loginurl, .params = pars, curl = curl)
h <- read_html(html)
id <- html_nodes(h, ".statsBtn")
id <- html_attr(id, "href")
id.vec <- sapply(strsplit(id, "="), function(x) as.numeric(x[2]))
return(id.vec)
}