Scraping a complex HTML table into a data.frame in R

后端 未结 2 952
盖世英雄少女心
盖世英雄少女心 2020-12-17 01:10

I am trying to load wikipedia\'s data on US Supreme Court Justices into R:

library(rvest)

html = html(\"http://en.wikipedia.org/wiki/List_of_Justices_of_the         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-17 01:42

    You could use rvest

    library(rvest)
    
    html("http://en.wikipedia.org/wiki/List_of_Justices_of_the_Supreme_Court_of_the_United_States")%>%   
      html_nodes("span+ a") %>% 
      html_text()
    

    It's not perfect so you might want to refine the css selector but it gets you fairly close.

提交回复
热议问题