用rvest-足球统计数据在R圈刮球

用rvest-足球统计数据在R圈刮球,r,rvest,R,Rvest,我试图让R在transfermarket.com上循环浏览球员档案,我首先用以下内容获取球员名册URL #/ Add the Team’s URL to scrape TeamScrape <- read_html("http://www.transfermarkt.com/jumplist/startseite/verein/2778") #// Get Club Name ClubName <- TeamScrape %>% html_nodes(".spieler

我试图让R在transfermarket.com上循环浏览球员档案,我首先用以下内容获取球员名册URL

#/ Add the Team’s URL to scrape

TeamScrape <- read_html("http://www.transfermarkt.com/jumplist/startseite/verein/2778")


#// Get Club Name

ClubName <- TeamScrape %>%
html_nodes(".spielername-profil") %>%
html_text()

#// Get All Player URLs 

PlayerURLs <- TeamScrape %>%
html_nodes(".spielprofil_tooltip") %>%
html_attr("href")

PlayerURLs <- unique(PlayerURLs)
PlayerURLs <- na.omit(PlayerURLs)

PlayerURLs <- paste0("http://www.transfermarkt.com", PlayerURLs)

PlayerLinks = data.frame(ClubName, PlayerURLs)
#/添加团队的URL以进行刮取
TeamScrape%
html_text()
#//获取所有播放器URL
玩家百分比
html_节点(“.spielprofil_工具提示”)%>%
html_attr(“href”)
玩家百分比
html_text()
#//多巴哥
DOB%
html_节点(“.wsnw”)%>%
html_text()
#//年龄
年龄%
html_节点(“.profilheader.hide for small td”)%>%
html_text()%>%
as.numeric()
#//价值观
价值%
html_节点(“.marktwert a”)%>%
html_text()
#//本赛季的比赛
匹配%
html_节点(“.hide.hide for small+.zentriert”)%>%
html_text()%>%
as.numeric()
#//本赛季进球数
目标%
html#u节点(#yw1 tfoot.zentriert:n子节点(4)”)%>%
html_text()%>%
as.numeric()
#//本赛季助攻
助攻%
html_节点(“tfoot.zentriert:nth child(5)”)%>%
html_text()%>%
as.numeric()
#//明斯这个赛季打过球
分钟%
html_节点(“tfoot.zentriert:nth child(7)”)%>%
html_text()%>%
as.numeric()
#//对数据进行一些清理
#若要拆卸垫片,请不要更换

URLLink <- PlayerURLs[13]
最后加上

output
})

HubertL-感谢您的快速回复。我按照你说的做了,我得到了以下信息:data.frame中的错误(SquadNo,Name,national,Club,ContractUntil,Position,:参数表示不同的行数:0,1另外:警告消息:1:在函数列表[[k]](值):强制引入的NAs 2:在函数列表[[k]](值):强制引入的NAs 3:在函数列表[[k]](值):强制引入的NAs称为from:data.frame(SquadNo,Name,national,Club,ContractUntil,Position,DOB,Age)这是因为有些数据丢失奇怪,即使我将报废减少到2个因素,它说我在行值上有差异…我通过使用
rep()解决了这个问题
在固定字段上,该字段仅在标准输出中出现一次,并根据最长数据项的长度计算重复次数。如仍有必要,我可以提供完整答案。
lapply(PlayerURLs, FUN=function(URLLink){
output
})