You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用worldfootballR包从fbref获取欧冠赛事数据?

解决方法

正确调用fb_match_results的方式

之前的代码冗余参数导致函数解析出错,直接传入目标赛事的URL即可,不需要额外填country或season_end_year:

library(worldfootballR)

# 仅传入非国内联赛的赛程URL
cl_data <- fb_match_results(
  non_dom_league_url = "https://fbref.com/en/comps/8/2022-2023/schedule/2022-2023-Champions-League-Scores-and-Fixtures"
)

# 提取你需要的字段:主客队、比分、预期进球
target_data <- cl_data[, c("Home", "Away", "Score", "xG", "xG.1")]
# 重命名列让逻辑更清晰
colnames(target_data) <- c("主队", "客队", "全场比分", "主队预期进球", "客队预期进球")

print(target_data)

出错原因说明

  • 你之前传入的country = ''和season_end_year = '2023'属于国内联赛的匹配参数,会干扰函数对洲际赛事URL的解析,函数会优先走国内联赛的赛季匹配逻辑,导致无法读取传入的URL数据。
  • fb_match_urls用country = "UEFA"不合适,这个参数是给具体国家联赛用的,欧冠属于洲际赛事,不适用这个参数。

备选方案(如果worldfootballR调用仍有问题)

可以直接用rvest包解析网页获取数据:

library(rvest)

url <- "https://fbref.com/en/comps/8/2022-2023/schedule/2022-2023-Champions-League-Scores-and-Fixtures"
page <- read_html(url)

# 定位并提取赛程表格
schedule_table <- page %>% 
  html_element("table#sched_2022-2023_8_1") %>% 
  html_table(fill = TRUE)

# 筛选需要的列并整理
clean_table <- schedule_table[, c("Home", "Away", "Score", "xG", "xG.1")]
colnames(clean_table) <- c("主队", "客队", "全场比分", "主队预期进球", "客队预期进球")

print(clean_table)

内容的提问来源于stack exchange,提问作者Juan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 04:03:19