Harvest (rvest) mehrere HTML-Seiten aus einer Liste von URLs

Ich habe einen Datenrahmen, der so aussieht:

country <- c("Canada", "US", "Japan", "China")
url <- c("http://en.wikipedia.org/wiki/United_States", "http://en.wikipedia.org/wiki/Canada",
          "http://en.wikipedia.org/wiki/Japan", "http://en.wikipedia.org/wiki/China")
df <- data.frame(country, url)

    country link
1   Canada  http://en.wikipedia.org/wiki/United_States
2   US      http://en.wikipedia.org/wiki/Canada
3   Japan   http://en.wikipedia.org/wiki/Japan
4   China   http://en.wikipedia.org/wiki/China

Usingrvest Ich möchte das @ kratzInhaltsverzeichni für jede URL und binde sie an eine einzige Ausgabe.

Dieser Code extrahiert das Inhaltsverzeichnis für eine URL:

library(rvest)
toc <- html(url) %>%
  html_nodes(".toctext") %>%
  html_text()

Gewünschte Ausgabe:

country toc
US      Etymology
        History
        Native American and European contact
        Settlements
        ...  
Canada  Etymology
        History
        Aboriginal peoples
        European colonization
        ...etc

Antworten auf die Frage(2)

Ihre Antwort auf die Frage