使用rvest将刮表存储到变量中

时间:2017-09-15 14:53:56

标签: r rvest

如何将从html_table获得的输出存储到变量中?:

  library(rvest)


   elec<- 
   read_html("https://en.wikipedia.org/wiki/Botswana_general_election,_1969")

    elec%>%

   html_nodes("table.wikitable")%>% 
   html_table(fill=TRUE)

1 个答案:

答案 0 :(得分:1)

最小例子:

library(rvest)

    data <- read_xml("url")


    a <- data %>% xml_find_all("//node a") %>% xml_text() 
    b <- data %>% xml_find_all("//node b") %>% xml_text()

    df =  data.frame(a,b)