R中的readHTMLTable仅从basketball参考页返回前两个表

R中的readHTMLTable仅从basketball参考页返回前两个表,r,web-scraping,R,Web Scraping,我正试图从basketball-reference.com上抓取球队统计数据网页,但当我使用readHTML时,它只会带回前两个表格 我的R代码如下所示: url = "http://www.basketball-reference.com/leagues/NBA_2015.html" teamPageTables = readHTMLTable(url) 这将返回一个只有2个的列表。页面上最上面的两个表格。我希望有一个包含页面中所有表格的列表 我还尝试将rvest与我想要的表(杂项统计表)的

我正试图从basketball-reference.com上抓取球队统计数据网页,但当我使用readHTML时,它只会带回前两个表格

我的R代码如下所示:

url = "http://www.basketball-reference.com/leagues/NBA_2015.html"
teamPageTables = readHTMLTable(url)
这将返回一个只有2个的列表。页面上最上面的两个表格。我希望有一个包含页面中所有表格的列表

我还尝试将rvest与我想要的表(杂项统计表)的XPath一起使用,但也没有成功

BBR是否已更改某些内容以阻止刮擦。我甚至看到过其他关于删除团队站点的帖子,该站点指控他想要的表位于索引16处……我复制了他的代码,但仍然一无所获


任何帮助都将不胜感激。谢谢,

只有此网页有两个有效的html表。其他表作为html注释在页面中,可能会被一些javascript解析。您或许可以尝试分析这些注释

library(rvest)
url <- "http://www.basketball-reference.com/leagues/NBA_2015.html"
page <- read_html(url)

# there are two valid tables - get them with css id's
team_stats_per_game <- html_node(page, "#team-stats-per_game")
divs_standings_E <- html_nodes(page, "#divs_standings_E")

# look at the actual page text - open bb.html in a text editor
text <- readLines(url)
writeLines(text, "bb.html")
下面的代码显示查找两个有效表并将原始html写入文件。在文本编辑器中打开bb.html,注意其中有许多表
library(rvest)
url <- "http://www.basketball-reference.com/leagues/NBA_2015.html"
page <- read_html(url)

# there are two valid tables - get them with css id's
team_stats_per_game <- html_node(page, "#team-stats-per_game")
divs_standings_E <- html_nodes(page, "#divs_standings_E")

# look at the actual page text - open bb.html in a text editor
text <- readLines(url)
writeLines(text, "bb.html")
库(rvest)

url只有此网页有两个有效的html表。其他表作为html注释在页面中,可能会被一些javascript解析。您或许可以尝试分析这些注释

library(rvest)
url <- "http://www.basketball-reference.com/leagues/NBA_2015.html"
page <- read_html(url)

# there are two valid tables - get them with css id's
team_stats_per_game <- html_node(page, "#team-stats-per_game")
divs_standings_E <- html_nodes(page, "#divs_standings_E")

# look at the actual page text - open bb.html in a text editor
text <- readLines(url)
writeLines(text, "bb.html")
下面的代码显示查找两个有效表并将原始html写入文件。在文本编辑器中打开bb.html,注意其中有许多表
library(rvest)
url <- "http://www.basketball-reference.com/leagues/NBA_2015.html"
page <- read_html(url)

# there are two valid tables - get them with css id's
team_stats_per_game <- html_node(page, "#team-stats-per_game")
divs_standings_E <- html_nodes(page, "#divs_standings_E")

# look at the actual page text - open bb.html in a text editor
text <- readLines(url)
writeLines(text, "bb.html")
库(rvest)

url因为其他表在注释中,所以
readHTMLTable()
不会捕获它。但是,考虑用“代码>读取行< /代码>读取URL文本,然后删除注释标签<代码> <代码>,从中相应地解析文档。原来页面上有85张表格!下面摘录了屏幕上可立即查看的10个表格:

library(XML)

# READ URL TEXT
url <- "http://www.basketball-reference.com/leagues/NBA_2015.html"
urltxt <- readLines(url)
# REMOVE COMMENT TAGS
urltxt <- gsub("-->", "", gsub("<!--", "", urltxt))

# PARSE UNCOMMENTED TEXT
doc <- htmlParse(urltxt)

# RETRIEVE ALL <table> TAGS
tables <- xpathApply(doc, "//table")

# LIST OF DATAFRAMES
teamPageTables <- lapply(tables[c(1:2,19:26)], function(i) readHTMLTable(i))
库(XML)
#读取URL文本

url因为其他表在注释中,所以
readHTMLTable()
不会捕获它。但是,考虑用“代码>读取行< /代码>读取URL文本,然后删除注释标签<代码> <代码>,从中相应地解析文档。原来页面上有85张表格!下面摘录了屏幕上可立即查看的10个表格:

library(XML)

# READ URL TEXT
url <- "http://www.basketball-reference.com/leagues/NBA_2015.html"
urltxt <- readLines(url)
# REMOVE COMMENT TAGS
urltxt <- gsub("-->", "", gsub("<!--", "", urltxt))

# PARSE UNCOMMENTED TEXT
doc <- htmlParse(urltxt)

# RETRIEVE ALL <table> TAGS
tables <- xpathApply(doc, "//table")

# LIST OF DATAFRAMES
teamPageTables <- lapply(tables[c(1:2,19:26)], function(i) readHTMLTable(i))
库(XML)
#读取URL文本
网址