library(rvest)
library(stringr)
gamble = function(x){
url = str_c('http://cp.win007.com/buy/toto14.aspx?issueNum=',x)
session = url %>% html_session() %>% html_nodes("table") %>% .[[2]] %>%
html_nodes("td:nth-child(1)") %>% html_text() %>% .[-1]
场次 = session[seq(1,length(session),5)]
event = url %>% html_session() %>% html_nodes("table") %>% .[[2]] %>%
html_nodes("td:nth-child(2)") %>% html_text() %>% .[-1]
赛事 = event[seq(1,length(event),4)]
开赛时间 = url %>% html_session() %>% html_nodes("table") %>% .[[2]] %>%
html_nodes("td:nth-child(3)") %>% html_text() %>% .[-1]
主队 = url %>% html_session() %>% html_nodes("table") %>% .[[2]] %>%
html_nodes("td:nth-child(4)") %>% html_text() %>% .[-1] %>%
str_replace('\r\n\t\t\t','')
客队 = url %>% html_session() %>% html_nodes("table") %>% .[[2]] %>%
html_nodes("td:nth-child(5)") %>% html_text() %>% .[-1] %>%
str_replace('\r\n\t\t\t','')
分析 = url %>% html_session() %>% html_nodes("table") %>% .[[2]] %>%
html_nodes("td:nth-child(12)") %>% html_text() %>% .[-1] %>%
str_replace('\r\n\t\t\t\t','') %>% str_extract("亚 欧 析 统")
状态 = url %>% html_session() %>% html_nodes("table") %>% .[[2]] %>%
html_nodes("td:nth-child(13)") %>% html_text()
比分 = url %>% html_session() %>% html_nodes("table") %>% .[[2]] %>%
html_nodes("td:nth-child(14)") %>% html_text()
半场 = url %>% html_session() %>% html_nodes("table") %>% .[[2]] %>%
html_nodes("td:nth-child(15)") %>% html_text()
彩果 = url %>% html_session() %>% html_nodes("table") %>% .[[2]] %>%
html_nodes("td:nth-child(16)") %>% html_text()
基础信息 = data.frame(场次=场次,赛事=赛事,开赛时间=开赛时间,主队=主队,客队=客队,分析=分析,
状态=状态,比分=比分,半场=半场,彩果=彩果)
u = str_c('http://cp.win007.com/handle/handicap.aspx?issuenum=',x,'&typeid=1&companyid=3&1420858993000')
asia = u %>% html() %>% html_nodes("i") %>% html_text() %>% str_split(",") %>%
do.call(rbind,.) %>% .[,c(2,4,5,6)] %>% as.data.frame
asia = sapply(asia, function(x) as.numeric(as.character(x))) %>% as.data.frame
皇冠亚赔 = asia[order(asia[,1]),][-1]
v = str_c('http://cp.win007.com/handle/1x2.aspx?issuenum=',x,'&typeid=1&companyid=9&1420894723000')
uro = v %>% html() %>% html_nodes("i") %>% html_text() %>% str_split(",") %>%
do.call(rbind,.) %>% .[,c(2,7,8,9)] %>% as.data.frame
uro = sapply(uro, function(x) as.numeric(as.character(x))) %>% as.data.frame
威廉欧赔 = uro[order(uro[,1]),][-1]
l = str_c('http://cp.win007.com/handle/1x2.aspx?issuenum=',x,'&typeid=1&companyid=-3&t=1421656460000')
kaili = l %>% html() %>% html_nodes("i") %>% html_text() %>% str_split(",") %>%
do.call(rbind,.) %>% as.data.frame
kaili = sapply(kaili, function(x) as.numeric(as.character(x))) %>% as.data.frame
凯丽指数 = kaili[order(kaili[,1]),][-1]
b = str_c('http://cp.win007.com/handle/betfair.aspx?issuenum=',x,'&typeid=1&1421657087000')
bifa = b %>% html() %>% html_nodes("i") %>% html_text() %>% str_split(",") %>%
do.call(rbind,.) %>% as.data.frame
bifa = sapply(bifa, function(x) as.numeric(as.character(x))) %>% as.data.frame %>% .[c(-1,-5)]
必发指数 = bifa
total = cbind(基础信息,威廉欧赔,皇冠亚赔,凯丽指数,必发指数)
names(total) = c('场次','赛事','开赛时间','主队','客队','分析','状态','比分','半场','彩果','威廉1',
'威廉2','威廉3','皇冠1','皇冠2','皇冠3','凯丽1','凯丽2','凯丽3','必发1','必发2','必发3')
return(total)
}
gamble(2015003)
场次 赛事 开赛时间 主队 客队 分析 状态 比分 半场 彩果
13 1 英足总 01-06 03:45 伯恩利 热 刺 亚 欧 析 统 完场 1-1 0-0 平
12 2 英足总 01-06 03:55 温布尔 利物浦 亚 欧 析 统 完场 1-2 1-1 负
14 3 英足总 01-07 03:45 埃弗顿 西汉姆 亚 欧 析 统 完场 1-1 0-0 平
7 4 意甲 01-06 03:45 拉齐奥 桑普多 亚 欧 析 统 完场 3-0 2-0 胜
11 5 意甲 01-06 19:30 乌迪内 罗 马 亚 欧 析 统 完场 0-1 0-1 负
3 6 意甲 01-06 22:00 切 沃 都 灵 亚 欧 析 统 完场 0-0 0-0 平
8 7 意甲 01-06 22:00 AC米兰 萨索洛 亚 欧 析 统 完场 1-2 1-1 负
4 8 意甲 01-06 22:00 恩波利 维罗纳 亚 欧 析 统 完场 0-0 0-0 平
10 9 意甲 01-06 22:00 帕尔马 佛罗伦 亚 欧 析 统 完场 1-0 1-0 胜
5 10 意甲 01-06 22:00 热那亚 亚特兰 亚 欧 析 统 完场 2-2 0-1 平
9 11 意甲 01-06 22:00 巴勒莫 卡利亚 亚 欧 析 统 完场 5-0 3-0 胜
2 12 意甲 01-07 01:00 切塞纳 那不勒 亚 欧 析 统 完场 1-4 0-2 负
6 13 意甲 01-07 04:00 尤 文 国 米 亚 欧 析 统 完场 1-1 1-0 平
1 14 西甲 01-06 03:45 科尔多 格拉纳 亚 欧 析 统 完场 2-0 2-0 胜
威廉1 威廉2 威廉3 皇冠1 皇冠2 皇冠3 凯丽1 凯丽2 凯丽3 必发1 必发2 必发3
13 3.50 3.50 2.05 0.98 -0.25 0.92 93.5 93.4 93.4 3.40 3.70 2.32
12 12.00 5.50 1.25 0.99 -1.75 0.90 93.1 93.0 93.0 14.50 7.20 1.26
14 1.95 3.50 3.80 0.86 0.50 1.04 93.1 93.1 93.2 1.97 3.90 4.20
7 1.75 3.60 4.80 0.95 0.75 0.96 94.5 94.5 94.5 1.79 3.75 5.80
11 4.33 3.40 1.83 1.01 -0.50 0.91 94.6 94.6 94.6 4.90 3.60 1.94
3 3.00 2.90 2.60 1.02 0.00 0.90 94.7 94.6 94.6 3.05 3.15 2.84
8 1.60 4.00 5.50 1.08 1.00 0.84 94.6 94.6 94.6 1.65 4.20 6.60
4 1.91 3.50 4.00 0.87 0.50 1.05 94.5 94.5 94.5 1.93 3.75 4.60
10 3.80 3.40 2.00 0.96 -0.50 0.95 94.5 94.5 94.5 4.50 3.60 2.00
5 2.10 3.20 3.60 0.90 0.25 1.01 94.7 94.7 94.7 2.26 3.30 3.95
9 2.05 3.25 3.80 0.89 0.25 1.03 94.7 94.7 94.7 2.22 3.40 3.95
2 9.00 4.60 1.36 1.06 -1.25 0.86 94.6 94.6 94.6 11.50 5.30 1.37
6 1.44 4.33 7.50 1.06 1.25 0.86 94.7 94.7 94.7 1.47 4.80 9.40
1 2.50 2.87 3.20 1.20 0.25 0.75 94.5 94.5 94.5 2.62 3.15 3.30