【发布时间】:2016-11-14 06:22:32
【问题描述】:
我想以更精简的方式整理出许多 NBA Fantasy Projections。目前我在谷歌表格中使用 importhtml 函数和简单的古老的 cut'n'paste 的组合。
我经常使用 R 从互联网上抓取其他数据,但是,我无法设法抓取这些表格。我遇到问题的表格位于三个不同的地址(每页 1 个表格),它们是:
1) http://www.sportsline.com/nba/player-projections/player-stats/all-players/
2) https://swishanalytics.com/optimus/nba/daily-fantasy-projections
3)http://www.sportingcharts.com/nba/dfs-projections/
对于我所有其他的抓取活动,我使用包 rvest 和 xml。按照相同的过程,我尝试了下面列出的两种方法,结果显示了输出。我确定这与网站上表格的格式有关,但是我找不到可以帮助我的东西。
方法一
library(XML)
projections1 <- readHTMLTable("http://www.sportsline.com/nba/player-projections/player-stats/all-players/")
projections2 <- readHTMLTable("https://swishanalytics.com/optimus/nba/daily-fantasy-projections")
projections3 <- readHTMLTable("http://www.sportingcharts.com/nba/dfs-projections/")
输出
projections1
named list()
projections2
named list()
Warning message:
XML content does not seem to be XML: 'https://swishanalytics.com/optimus/nba/daily-fantasy-projections'
projections3 - 我得到了表格的标题,但没有得到表格的内容。
方法二
library(rvest)
URL <- "http://www.sportsline.com/nba/player-projections/player-stats/all-players/"
projections1 <- URL %>%
read_html %>%
html_nodes("table") %>%
html_table(trim=TRUE,fill=TRUE)
URL <- "https://swishanalytics.com/optimus/nba/daily-fantasy-projections"
projections2 <- URL %>%
read_html %>%
html_nodes("table") %>%
html_table(trim=TRUE,fill=TRUE)
URL <- "http://www.sportingcharts.com/nba/dfs-projections/"
projections3 <- URL %>%
read_html %>%
html_nodes("table") %>%
html_table(trim=TRUE,fill=TRUE)
输出
projections1
list()
projections2 - 我得到了表格的标题,但没有得到表格的内容。
projections3 - 我得到了表格的标题,但没有得到表格的内容。
如果有人能指出我正确的方向,将不胜感激。
【问题讨论】: