【问题标题】:How can I extract this specific table from this web page using R?如何使用 R 从此网页中提取此特定表?
【发布时间】:2022-01-01 10:02:06
【问题描述】:

我正在尝试从特定网页中提取表格,但没有从我的代码中获得任何结果。

我的代码如下:

library(rvest)
library(dplyr)

url1<-"https://finance.yahoo.com/quote/SKLZ/cash-flow?p=SKLZ"

url_page<- read_html(url1)

listings <- html_nodes(url_page, css = '.Pos')

我有兴趣提取的表属于(在 Chrome 中进行“检查”之后)。

这是表格的截图:

任何帮助将不胜感激。

【问题讨论】:

    标签: r web-scraping rvest


    【解决方案1】:

    [QHarr] has answered the same question in this post我已经从他们的回答中复制了相关代码。

    library(rvest)
    library(stringr)
    library(magrittr)
    
    page <- read_html("https://finance.yahoo.com/quote/SKLZ/cash-flow?p=SKLZ")
    nodes <- page %>%html_nodes(".fi-row")
    df = NULL
    
    for(i in nodes){
      r <- list(i %>%html_nodes("[title],[data-test='fin-col']")%>%html_text())
      df <- rbind(df,as.data.frame(matrix(r[[1]], ncol = length(r[[1]]), byrow = TRUE), stringsAsFactors = FALSE))
    }
    
    df
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-20
      • 1970-01-01
      • 2013-11-16
      • 1970-01-01
      • 2022-11-18
      • 2021-11-29
      • 1970-01-01
      相关资源
      最近更新 更多