Lineups.com 上的表格是什么格式以及如何在 R 中抓取它

发布于 2025-01-11 20:47:02 字数 1081 浏览 0 评论 0原文

我是抓取新手,并已成功从这些网站抓取表格:-

https://www.numberfire.com/nba/daily-fantasy/daily-basketball-projections/guards
https://www.dailyfantasyfuel.com/nba/projections/draftkings/
https://www.sportsline.com/nba/expert-projections/simulation/

但是这个网站:-

https://www.lineups.com/nba/nba-fantasy -篮球投影

似乎非常棘手。

1.我尝试将其读取为 JSON

r <- read_html('https://www.lineups.com/nba/nba-fantasy-basketball-projections/' ) %>% html_element('script#__NEXT_DATA__') %>% html_text() %>% jsonlite::parse_json()

2.来自 rvest 方法

    data <- "https://www.lineups.com/nba/nba-fantasy-basketball-projections" %>%
      read_html %>%
      html_nodes('script') %>%
      html_text()

3.以及RSelenium,但没有成功。

您能告诉我如何处理在“www.lineups.com”上找到的这些类型的表吗?

谢谢

I am new to scraping and have successfully scraped tables from these websites:-

https://www.numberfire.com/nba/daily-fantasy/daily-basketball-projections/guards
https://www.dailyfantasyfuel.com/nba/projections/draftkings/
https://www.sportsline.com/nba/expert-projections/simulation/

But this website:-

https://www.lineups.com/nba/nba-fantasy-basketball-projections

seems very tricky.

1. I have tried to read it as JSON

r <- read_html('https://www.lineups.com/nba/nba-fantasy-basketball-projections/') %>% html_element('script#__NEXT_DATA__') %>% html_text() %>% jsonlite::parse_json()

2. from rvest methods

    data <- "https://www.lineups.com/nba/nba-fantasy-basketball-projections" %>%
      read_html %>%
      html_nodes('script') %>%
      html_text()

3. As well as RSelenium but with no success.

Could you kindly tell me how to deal with these kinds of Tables found at "www.lineups.com" ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不寐倦长更 2025-01-18 20:47:02

使用RSelenium

library(RSelenium)
library(rvest)
library(dplyr)
driver = rsDriver(browser = c("firefox"))

remDr <- driver[["client"]]

url <- 'https://www.lineups.com/nba/nba-fantasy-basketball-projections'
remDr$navigate(url)

#get all the tables from webapage 
df = remDr$getPageSource()[[1]] %>% 
    read_html() %>% html_table()
[[2]]
# A tibble: 51 x 31
   Player   Player Player Player Player Player Player Player ``    ``    ``    ``    ``    ``    Game  Game  Game  Game  Game  `Projected Game~ `Projected Game~
   <chr>    <chr>  <chr>  <chr>  <chr>  <chr>  <chr>  <chr>  <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>            <chr>           
 1 "Name"   Team   Pos    Proje~ Salary Pts/$~ FPPM   USG%   Pos   Proj~ Sala~ Pts/~ FPPM  USG%  Opp   DvP   Spre~ Total O/U   MINS             PTS             
 2 "Nikola~ DEN    C      58.37  $11,0~ 5.3    1.8    31.3%  HOU   30    13.5  126   238   33    27.7  7.7   13.7  1.1   0.9   5                18.8            
 3 "Gianni~ MIL    PF     57.84  $11,3~ 5.1    1.8    35.1%  CHI   27    -5    122.~ 240   33    30.5  5.9   11.7  1     1.4   7.8              19.1            
 4 "Joel E~ PHI    C      53.35  $10,8~ 4.9    1.7    37.4%  CLE   5     7     112   216.5 32    29.4  4.2   11    0.9   1.4   8.9              19     

Using RSelenium

library(RSelenium)
library(rvest)
library(dplyr)
driver = rsDriver(browser = c("firefox"))

remDr <- driver[["client"]]

url <- 'https://www.lineups.com/nba/nba-fantasy-basketball-projections'
remDr$navigate(url)

#get all the tables from webapage 
df = remDr$getPageSource()[[1]] %>% 
    read_html() %>% html_table()
[[2]]
# A tibble: 51 x 31
   Player   Player Player Player Player Player Player Player ``    ``    ``    ``    ``    ``    Game  Game  Game  Game  Game  `Projected Game~ `Projected Game~
   <chr>    <chr>  <chr>  <chr>  <chr>  <chr>  <chr>  <chr>  <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>            <chr>           
 1 "Name"   Team   Pos    Proje~ Salary Pts/$~ FPPM   USG%   Pos   Proj~ Sala~ Pts/~ FPPM  USG%  Opp   DvP   Spre~ Total O/U   MINS             PTS             
 2 "Nikola~ DEN    C      58.37  $11,0~ 5.3    1.8    31.3%  HOU   30    13.5  126   238   33    27.7  7.7   13.7  1.1   0.9   5                18.8            
 3 "Gianni~ MIL    PF     57.84  $11,3~ 5.1    1.8    35.1%  CHI   27    -5    122.~ 240   33    30.5  5.9   11.7  1     1.4   7.8              19.1            
 4 "Joel E~ PHI    C      53.35  $10,8~ 4.9    1.7    37.4%  CLE   5     7     112   216.5 32    29.4  4.2   11    0.9   1.4   8.9              19     
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文