I\'m trying to run some scraping where the action I take on a node is conditional on the contents of the node.
This should be a minimal example:
XML
An alternate approach:
library(tidyverse)
library(rvest)
XML <- '
Really L...
Short
'
pg <- read_html(XML)
html_nodes(pg, "td[class='id-tag']") %>%
map_chr(function(x) {
if (xml_find_first(x, "boolean(.//span)")) {
x <- html_nodes(x, xpath=".//span/@title")
}
html_text(x)
})
## [1] "Really Long Text" "Short"