Rvest: how to find all classes used in an HTML page?

I would like to find all the classes used on the web page below. Is this possible with rvest or will I need some kind of regex / grepl? I can clear the information as soon as I know the class name, but for pages with dynamically constructed class names it would be convenient to get an overview of the classes used.

library(rvest)

doc_url<-"http://curia.europa.eu/juris/document/document.jsf?text=&docid=160583&pageIndex=0&doclang=fr&mode=req&dir=&occ=first&part=1&cid=676771"

page<-read_html(doc_url)

language<- page%>%html_nodes(".C49FootnoteLangue")%>%html_text()
+4
source share
1 answer

By converting a @hadley comment into a CW response, you can get the vector of all classes using a wildcard *.

So the approach would look like this:

page <- read_html(doc_url)

page %>% 
  html_nodes("*") %>% 
  html_attr("class") %>% 
  unique()
#  [1] NA                          "component"                 "waitBlock"
#  [4] "waitBlockContainer"        "toggle_img"                "btn_impression"
#  [7] "document_language"         "outputEcli"                "C19Centre"
# [10] "C71Indicateur"             "C02AlineaAltA"             "C72Alineadroite"
# [13] "C75Debutdesmotifs"         "C01PointnumeroteAltN"      "C04Titre1"
# [16] "C03Tiretlong"              "C05Titre2"                 "C06Titre3"
# [19] "C07Titre4"                 "C48DispositifIntroduction" "C08Dispositif"
# [22] "C77Signatures"             "C49FootnoteLangue"
+4
source

Source: https://habr.com/ru/post/1622357/


All Articles