使用 rvest 从体育网站抓取数据表

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

我正在尝试从下一页抓取比赛表

https://www.nrl.com/ladder/?competition=111&round=27&season=2023

我使用了以下内容,但返回了 NULL 结果

url <- paste0("https://www.nrl.com/draw//data?competition=111&round=",27,"&season=2023")

contentnodes <- url %>% 
  html_nodes ("div.l-content.pre-quench") %>%
  html_attr("q-data") %>% 
  jsonlite::fromJSON()

有人可以告诉我我缺少什么吗?预先感谢

r web-scraping rvest
1个回答
0
投票

看起来页面是使用 javascript 绘制的,但看起来数据包含在 html 正文中。

试试这个:

library(rest)
url <- paste0("https://www.nrl.com/draw/data?competition=111&round=",27,"&season=2023")
#read page
page <- read_html(url)

#obtain the body and convert from json
body <-page %>% html_elements("body") %>% html_text()
jsonlite::fromJSON(body)
© www.soinside.com 2019 - 2024. All rights reserved.