我试图从fbref.com网站中提取一些足球数据,具体来说,我应该提取一些日期,我想了解如何过滤网站内的各个节点你好,我想从fbref提取一些数据,但我不能只提取某种类型的数据。我将通过附加有问题的html代码更好地解释:
<th scope="row" class="left " data-stat=**"date"** csk="20230819"><a href="/it/partite/254420f7/Internazionale-Monza-19-Agosto-2023-Serie-A">19-08-2023</a></th>
<a href="/it/partite/254420f7/Internazionale-Monza-19-Agosto-2023-Serie-A">19-08-2023</a>
字符串
阅读代码:
url <- https://fbref.com/it/squadre/d609edc0/Statistiche-Internazionale
html_data <- read_html(url)
html_data %>%
html_nodes(".left ")
型
它读取或多或少1266个不同的节点,但我只对提取“data-stats ='date'”的文本感兴趣。通过只获取这些节点,我应该能够稍后提取“href”之后的日期。
1条答案
按热度按时间yacmzcpb1#
可以使用
html_attr()
函数提取属性中的值,并检查它是否是所需的值。字符串
或者用一句话来表达:
型