Für eine Seite title werden die in props definierten Informationen aus der MediaWiki API abgerufen. Eine Dokumentation der Parameter für den API Aufruf GET(..., query=list(...)) findet sich hier: https://www.mediawiki.org/wiki/API:Properties.
f_get_pageinfo = function(title, props=c("contributors", "extlinks", "images", "info", "langlinks", "links", "linkshere", "redirects", "templates"), language="de", verbose = T,
pclimit = 500, # Max. contributors
pcexcludegroup = "bot", #no bots
ellimit = 500, # Max. external links
imlimit = 500, # Max. images
lllimit = 500, # Max. Language links
plnamespace = 0, pllimit = 500, # Namespaces of outgoing wikilinks (0="normale" Artikel), max. outgoing wikilinks
lhnamespace = 0, lhlimit = 500, lhshow = "!redirect", # Namespaces of ingoing wikilinks (0="normale" Artikel), max. ingoing wikilinks, keine redirects zeigen (läuft über prop=redirects)
rdlimit = 500, # Max. redirects
tllimit = 500 # Max templates
) {
if(verbose) print(title) # verbose: Ausgabe des Titels der abgefragten Seite (informativ für Listenabfrage)
domain = paste0("http://", language, ".wikipedia.org/w/api.php") #URL der API einer Wikipedia-Sprachversion
dmp = GET(domain, query=list( #Konstruktion des API Aufrufs
format = "json",
action = "query",
titles = title,
prop = paste0(props, collapse = "|"),
inprop = "protection|talkid",
pcexcludegroup = pcexcludegroup, pclimit = pclimit,
ellimit = ellimit,
imlimit = imlimit,
lllimit = lllimit,
plnamespace = plnamespace, pllimit = pllimit,
lhnamespace = lhnamespace, lhshow = lhshow, lhlimit = lhlimit,
rdlimit = rdlimit,
tllimit = tllimit))
dmp = content(dmp, as = "text") #Abruf des Ergebnisses der API Abfrage
dmp = RCurl:::mapUnicodeEscapes(dmp) #Codierung der Unicode Escape Characters
dmp = fromJSON(dmp) #Umwandlen des json Objekts in R kompatible Daten
results = dmp$query$pages[[1]] # Auswahl der relevanten Informationen
# Die API gibt in einem Aufruf für jede angeforderte Information nur die ersten "XXlimit" (maximal 500) Angaben zurück. Wenn es weitere Informationen gibt, wird ein Code geliefert, der angibt, wo ein weiterer Abruf beginnen muss. So lange ein solcher Code zurückgegeben wird, führen wir weitere Abrufe aus, bis alle Seiten gesammelt wurden.
while (!is.null(dmp$"query-continue")) {
what = names(dmp$"query-continue")
dmp = GET(domain, query=list(
format = "json",
action = "query",
titles = title,
prop = paste0(what, collapse = "|"),
pcexcludegroup = pcexcludegroup, pclimit = pclimit, pccontinue = dmp$"query-continue"$contributors[[1]],
ellimit = ellimit, eloffset = dmp$"query-continue"$extlinks[[1]],
imlimit = imlimit, imcontinue = dmp$"query-continue"$images[[1]],
lllimit = lllimit, llcontinue = dmp$"query-continue"$langlinks[[1]],
plnamespace = plnamespace, pllimit = pllimit, plcontinue = dmp$"query-continue"$links[[1]],
lhnamespace = lhnamespace, lhshow = lhshow, lhlimit = lhlimit, lhcontinue = dmp$"query-continue"$linkshere[[1]],
rdlimit = rdlimit, rdcontinue = dmp$"query-continue"$redirects[[1]],
tllimit = tllimit, tlcontinue = dmp$"query-continue"$templates[[1]]))
dmp = content(dmp, as = "text")
dmp = RCurl:::mapUnicodeEscapes(dmp)
dmp = fromJSON(dmp)
for (i in what) { # Neu abgerufene Informationen zu bisher abgerufenen Informationen hinzufügen
results[[i]] = rbind(results[[i]], dmp$query$pages[[1]][[i]])
}
}
results
}
Informationen zum Artikel “Durchfall”
durchfall.infos = f_get_pageinfo(title = "Durchfall", verbose = F)
str(durchfall.infos) #Überblick über gesammelte Informationen
## List of 20
## $ pageid : num 46426
## $ ns : num 0
## $ title : chr "Durchfall"
## $ anoncontributors: chr "86"
## $ contributors :'data.frame': 193 obs. of 2 variables:
## ..$ userid: chr [1:193] "142" "568" "756" "1330" ...
## ..$ name : chr [1:193] "Nerd" "Aka" "Ahoerstemeier" "El" ...
## $ extlinks :'data.frame': 8 obs. of 1 variable:
## ..$ *: chr [1:8] "//commons.wikimedia.org/wiki/Category:Diarrhea?uselang=de" "http://dx.doi.org/10.1111%2Fj.1742-1241.2009.02051.x" "http://libdoc.who.int/hq/2006/WHO_FCH_CAH_06.1.pdf" "http://rehydrate.org/ors/made-at-home.htm" ...
## $ images :'data.frame': 3 obs. of 2 variables:
## ..$ ns : num [1:3] 6 6 6
## ..$ title: chr [1:3] "Datei:Commons-logo.svg" "Datei:Disambig-dark.svg" "Datei:Rod of asclepius left drk.svg"
## $ contentmodel : chr "wikitext"
## $ pagelanguage : chr "de"
## $ touched : chr "2014-10-06T07:17:27Z"
## $ lastrevid : num 1.35e+08
## $ counter : chr ""
## $ length : num 23436
## $ protection :'data.frame': 4 obs. of 3 variables:
## ..$ type : chr [1:4] "edit" "move" "edit" "move"
## ..$ level : chr [1:4] "autoconfirmed" "autoconfirmed" "autoconfirmed" "autoconfirmed"
## ..$ expiry: chr [1:4] "infinity" "infinity" "infinity" "infinity"
## $ talkid : num 313304
## $ langlinks :'data.frame': 77 obs. of 2 variables:
## ..$ lang: chr [1:77] "af" "ang" "ar" "ast" ...
## ..$ * : chr [1:77] "Diarree" "Meteūtsiht" "إسهال" "Foria" ...
## $ links :'data.frame': 126 obs. of 2 variables:
## ..$ ns : num [1:126] 0 0 0 0 0 0 0 0 0 0 ...
## ..$ title: chr [1:126] "Altgriechische Sprache" "Amyloidose" "Amöbiasis" "Anamnese" ...
## $ linkshere :'data.frame': 525 obs. of 3 variables:
## ..$ pageid: chr [1:525] "179" "212" "295" "489" ...
## ..$ ns : num [1:525] 0 0 0 0 0 0 0 0 0 0 ...
## ..$ title : chr [1:525] "Augustus" "Ergotismus" "Ascorbinsäure" "Barium" ...
## $ redirects :'data.frame': 4 obs. of 3 variables:
## ..$ pageid: chr [1:4] "58532" "58533" "191608" "4472508"
## ..$ ns : num [1:4] 0 0 0 0
## ..$ title : chr [1:4] "Diarrhoe" "Diarrhö" "Diarrhöe" "Antidiarrhoika"
## $ templates :'data.frame': 24 obs. of 2 variables:
## ..$ ns : num [1:24] 10 10 10 10 10 10 10 10 10 10 ...
## ..$ title: chr [1:24] "Vorlage:Bausteindesign1" "Vorlage:Bausteindesign2" "Vorlage:Booland3" "Vorlage:Boolandnot" ...
Informationen über eine Liste von Artikeln
article.list = c("Fieber", "Durchfall", "Husten")
article.list.infos = lapply(article.list, f_get_pageinfo)
## [1] "Fieber"
## [1] "Durchfall"
## [1] "Husten"
names(article.list.infos) = article.list
str(article.list.infos, max.level = 2) #Überblick über gesammelte Informationen
## List of 3
## $ Fieber :List of 20
## ..$ pageid : num 1778
## ..$ ns : num 0
## ..$ title : chr "Fieber"
## ..$ anoncontributors: chr "277"
## ..$ contributors :'data.frame': 245 obs. of 2 variables:
## ..$ extlinks :'data.frame': 40 obs. of 1 variable:
## ..$ images :'data.frame': 7 obs. of 2 variables:
## ..$ contentmodel : chr "wikitext"
## ..$ pagelanguage : chr "de"
## ..$ touched : chr "2014-10-06T12:07:32Z"
## ..$ lastrevid : num 1.35e+08
## ..$ counter : chr ""
## ..$ length : num 57819
## ..$ protection : list()
## ..$ talkid : num 1779
## ..$ langlinks :'data.frame': 85 obs. of 2 variables:
## ..$ links :'data.frame': 198 obs. of 2 variables:
## ..$ linkshere :'data.frame': 555 obs. of 3 variables:
## ..$ redirects :'data.frame': 9 obs. of 3 variables:
## ..$ templates :'data.frame': 11 obs. of 2 variables:
## $ Durchfall:List of 20
## ..$ pageid : num 46426
## ..$ ns : num 0
## ..$ title : chr "Durchfall"
## ..$ anoncontributors: chr "86"
## ..$ contributors :'data.frame': 193 obs. of 2 variables:
## ..$ extlinks :'data.frame': 8 obs. of 1 variable:
## ..$ images :'data.frame': 3 obs. of 2 variables:
## ..$ contentmodel : chr "wikitext"
## ..$ pagelanguage : chr "de"
## ..$ touched : chr "2014-10-06T07:17:27Z"
## ..$ lastrevid : num 1.35e+08
## ..$ counter : chr ""
## ..$ length : num 23436
## ..$ protection :'data.frame': 4 obs. of 3 variables:
## ..$ talkid : num 313304
## ..$ langlinks :'data.frame': 77 obs. of 2 variables:
## ..$ links :'data.frame': 126 obs. of 2 variables:
## ..$ linkshere :'data.frame': 525 obs. of 3 variables:
## ..$ redirects :'data.frame': 4 obs. of 3 variables:
## ..$ templates :'data.frame': 24 obs. of 2 variables:
## $ Husten :List of 20
## ..$ pageid : num 69353
## ..$ ns : num 0
## ..$ title : chr "Husten"
## ..$ anoncontributors: chr "120"
## ..$ contributors :'data.frame': 115 obs. of 2 variables:
## ..$ extlinks :'data.frame': 4 obs. of 1 variable:
## ..$ images :'data.frame': 3 obs. of 2 variables:
## ..$ contentmodel : chr "wikitext"
## ..$ pagelanguage : chr "de"
## ..$ touched : chr "2014-10-05T11:39:25Z"
## ..$ lastrevid : num 1.33e+08
## ..$ counter : chr ""
## ..$ length : num 8092
## ..$ protection : list()
## ..$ talkid : num 1284083
## ..$ langlinks :'data.frame': 73 obs. of 2 variables:
## ..$ links :'data.frame': 70 obs. of 2 variables:
## ..$ linkshere :'data.frame': 166 obs. of 3 variables:
## ..$ redirects :'data.frame': 2 obs. of 3 variables:
## ..$ templates :'data.frame': 5 obs. of 2 variables: