I am new to rvest. How do I extract those elements with 2 class names or only 1 class name in tag?
This is my code and issue:
doc <- paste(\"
You can use css selector as follows:
Select class contains b1
not a1
:
read_html(doc) %>% html_nodes(".b1:not(.a1)")
# {xml_nodeset (1)}
# [1] text2
Or use the attribute selector:
read_html(doc) %>% html_nodes("[class='b1']")
# {xml_nodeset (1)}
# [1] text2
Select class contains both:
read_html(doc) %>% html_nodes(".a1.b1")
# {xml_nodeset (1)}
# [1] text1