如何使用 R 中的 WikipediaR 包从维基百科页面获取数据?

How to get data from Wikipedia page using WikipediR package in R?

我需要从多个维基百科页面中获取特定部分的数据。我怎样才能使用 WikipediR 包做到这一点?或者是否有其他更好的选择。准确地说,我只需要所有页面中以下标记的部分。

我怎样才能得到它?任何帮助,将不胜感激。

你能说得更具体一点吗?这是从网络导入数据的简单方法,特别是从维基百科。

library(rvest)    
scotusURL <- "https://en.wikipedia.org/wiki/List_of_Justices_of_the_Supreme_Court_of_the_United_States"

## ********************
## Option 1: Grab the tables from the page and use the html_table function to extract the tables you're interested in.

temp <- scotusURL %>% 
  html %>%
  html_nodes("table")

html_table(temp[1]) ## Just the "legend" table
html_table(temp[2]) ## THE MAIN TABLE

现在,如果您想从具有基本相同结构的多个页面导入数据,但可能只是改变了一些数字或其他内容,请尝试这种方法。

library(RCurl);library(XML)

pageNum <- seq(1:10)
url <- paste0("http://www.totaljobs.com/JobSearch/Results.aspx?Keywords=Leadership&LTxt=&Radius=10&RateType=0&JobType1=CompanyType=&PageNum=") 
urls <- paste0(url, pageNum) 

allPages <- lapply(urls, function(x) getURLContent(x)[[1]])
xmlDocs <- lapply(allPages, function(x) XML::htmlParse(x))