如果没有表标签,如何在R中使用html_表来刮表?
我一直在尝试从yahoo.finance中刮表,当我检查并找到所需的部分时,代码中没有表标记。我可以用html_文本函数提取数据,但不能用html_表格函数。 [如果没有表标签,如何在R中使用html_表来刮表?,html,r,web-scraping,rvest,finance,Html,R,Web Scraping,Rvest,Finance,我一直在尝试从yahoo.finance中刮表,当我检查并找到所需的部分时,代码中没有表标记。我可以用html_文本函数提取数据,但不能用html_表格函数。 [ link[https://stackoverflow.com/questions/58315274/r-web-scraping-yahoo-finance-after-2019-change][1] “解决您的问题。根据链接中的讨论,您可以获得“AAPL”的以下信息: 库(rvest) 图书馆(tidyverse) 抽搐 lib
link[https://stackoverflow.com/questions/58315274/r-web-scraping-yahoo-finance-after-2019-change][1] “解决您的问题。根据链接中的讨论,您可以获得“AAPL”的以下信息:
库(rvest)
图书馆(tidyverse)
抽搐
library(rvest)
library(tidyverse)
tic <- "AAPL"
link <- "https://finance.yahoo.com/quote/"
link <- paste0(link, tic, "/financials?p=", tic)
wahis.session <- html_session(link)
p <- wahis.session
nodes <- p %>% 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))
}
matches <- str_match_all(p1%>%html_node('#Col1-1-Financials-Proxy')%>%html_text(),'\\d{1,2}/\\d{1,2}/\\d{4}')
headers <- c('Breakdown','TTM', matches[[1]][,1])
names(df) <- headers