的人試圖從該網站湊根據以往的問題,可能是動態生成此表。據我所知,處理這樣的頁面的唯一方法是使用RSelenium
- 這基本上可以自動瀏覽器。
大量的試驗和錯誤後,下面的代碼似乎工作(使用Chrome在Windows 10)...
library(RSelenium)
library(rvest)
library(dplyr)
url <- "http://www.oddsportal.com/american-football/usa/nfl-2012-2013/results/"
rD <- rsDriver(port=4444L,browser="chrome")
remDr <- rD$client
remDr$navigate(url)
page <- remDr$getPageSource()
remDr$close() #you can leave open if you are doing several of these: close at the end
table <- page[[1]] %>%
read_html() %>%
html_nodes(xpath='//table[@id="tournamentTable"]') %>% #specify table as there is a div with same id
html_table(fill = T)
table <- table[[1]]
head(table)
American Football» USA»NFL 2012/2013 American Football» USA»NFL 2012/2013 American Football» USA»NFL 2012/2013 American Football» USA»NFL 2012/2013 American Football» USA»NFL 2012/2013 American Football» USA»NFL 2012/2013
1 03 Feb 2013 - Play Offs 03 Feb 2013 - Play Offs 03 Feb 2013 - Play Offs 03 Feb 2013 - Play Offs 1.00 2.00
2 NA NA
3 23:30 San Francisco 49ers - Baltimore Ravens San Francisco 49ers - Baltimore Ravens 31:34 1.49 2.71
4 28 Jan 2013 - All Stars 28 Jan 2013 - All Stars 28 Jan 2013 - All Stars 28 Jan 2013 - All Stars 1.00 2.00
5 NA NA
6 00:00 NFC - AFC NFC - AFC 62:35 2.03 1.83
American Football» USA»NFL 2012/2013
1 B's
2
3 9
4 B's
5
6 9
勝算出來十進制數,很遺憾,但希望你能與此一起工作。
非常感謝!我以爲RSelenium是用來在頁面中導航的。 (點擊按鈕等) –