【发布时间】:2020-07-07 13:38:51
【问题描述】:
我正在尝试使用 RStudio 收集为足球队效力的球员的标准统计数据。我能够将信息提取到列表中,但无法将它们可视化为数据框,它给了我这个错误(错误(函数(...,row.names = NULL,check.rows = FALSE,check.names =真,: 参数意味着不同的行数:33、27、24、35、5、4、54、38、18、2、1)我是 R 中的菜鸟,我想不出解决它的方法,这是我正在使用的代码,以及我试图从中提取数据的页面,非常欢迎任何帮助!!!
https://fbref.com/en/squads/2b390eca/2016-2017/Athletic-Bilbao
install.packages('rvest')
install.packages('plyr')
install.packages('dplyr')
library(rvest)
library(plyr)
library(dplyr)
years = c(2017:2018)
urls = list()
for (i in 1:length(years)) {
url = paste0('https://fbref.com/en/squads/2b390eca/',years[i],'-',years[i+1],'/Athletic-Bilbao')
urls[[i]] = url #https://fbref.com/en/squads/d5348c80/',years1[i],'-',years2[i+1],'/AEK-Athens
}
tbl = list()
years = 2017
j = 1
for (j in seq_along(urls)) {
tbl[[j]] = urls[[j]] %>%
read_html() %>%
html_nodes("table") %>%
html_table()
tbl[[j]]$Year = years
j = j+1
years = years+1
}
Data = ldply(tbl,data.frame)
【问题讨论】:
标签: r dataframe web-scraping rvest