正则表达式替换足球数据的多列

问题描述 投票:0回答:1

我一直在尝试使用谷歌表格导入,从网址https://www.pro-football-reference.com/years/2024/https://www 中抓取各种球队表数据,但没有成功.pro-football-reference.com/years/2024/opp.htm

我从另一篇文章中找到了此代码。

在简单的网页抓取查询上使用 Google Sheets 的 ImportXML XPath 问题

它非常接近我的需求,但我无法将其调整为来自同一网站的类似数据。

查询部分提取正确的未解析数据。

QUERY(IMPORTDATA("https://www.pro-football-reference.com/years/2024/");"选择 Col1,其中 Col1 包含 'exp_pts_rush'")

所以我相信我对 REGEXREPLACE 的误解是问题所在。

如有任何帮助,我们将不胜感激

=ARRAYFORMULA(SPLIT(QUERY(ARRAYFORMULA(REGEXREPLACE(REGEXREPLACE(ARRAYFORMULA(SUBSTITUTE(QUERY(IMPORTDATA("https://www.pro-football-reference.com/years/2024/")));"选择 Col1,其中 Col1 包含 'exp_pts_rush '");">";">0"));".+排名.+?>(.+?)<.+team.+([A-Z]{3}).+g.+?>(.+?)<.+?rush.+?>(.+?)<.+?rush.+?>(.+?)<.+?rush.+?>(.+ ?)<.+?rush.+?>(.+?)<.+?rush.+?>(.+?)<.+?rush.+?>(.+?)<.+?fum.+?>(.+?)<.+?exp.+";"$1;$2;$3;$4;$5;$6;$7;$8;$9;$10;$11"));"select * WHERE NOT Col1 contains '<'");";"))

我希望能有这样的结果;

google-sheets
1个回答
0
投票

这是您可以测试的一种方法:

=let(Σ,tocol(split(choosecols(importxml("https://www.pro-football-reference.com/years/2024","//*[@id='all_rushing']"),3),char(10))),
 filter(substitute(split(regexreplace(Σ,"([a-z])( )([A-Za-z]+\d+|\d+[a-zA-Z]+|[A-Z])","$1🌀$3")," "),"🌀"," "),regexmatch(Σ,"^\d+ ")))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.