rvest - scrape 2 classes in 1 tag rvest - scrape 2 classes in 1 tag r r

rvest - scrape 2 classes in 1 tag


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] <span class="b1"> text2 </span>

Or use the attribute selector:

read_html(doc) %>% html_nodes("[class='b1']")# {xml_nodeset (1)}# [1] <span class="b1"> text2 </span>

Select class contains both:

read_html(doc) %>% html_nodes(".a1.b1")# {xml_nodeset (1)}# [1] <span class="a1 b1"> text1 </span>