Importing wikipedia tables in R

后端 未结 4 391
别跟我提以往
别跟我提以往 2021-01-01 15:31

I regularly extract tables from Wikipedia. Excel\'s web import does not work properly for wikipedia, as it treats the whole page as a table. In google spreadsheet, I can ent

4条回答
  •  南方客
    南方客 (楼主)
    2021-01-01 16:22

    Building on Andrie's answer, and addressing SSL. If you can take one additional library dependency:

    library(httr)
    library(XML)
    
    url <- "https://en.wikipedia.org/wiki/Upper_Peninsula_of_Michigan"
    
    r <- GET(url)
    
    doc <- readHTMLTable(
      doc=content(r, "text"))
    
    doc[6]
    

提交回复
热议问题