I would like to scrape all headlines and the corresponding paragraph/text after a headline. My web document has several headlines. Finally, all text data should be ready for analysis in a dataframe. Headlines as h2 or belong to class mw-headline. I tried various sibling/children options, none worked so far.
library(rvest)
# define url
url <- "https://de.wikisource.org/wiki/Die_Gartenlaube_(1853)/Heft_1"
# download content
html_document <- read_html(url)
html_document %>%
# extract headlines
html_nodes("h2") %>%
# extract text
html_text() -> title
html_document %>%
# extract paragraphs
html_nodes("p") %>%
# extract text
html_text() -> text