I'm not sure how to describe a problem so I will go directly to the example.
I have a HTML document (html_doc) that looks like:
<div class="main">
<h2>A</h2>
<div class="route">
X<br />
</div>
<div class="route">
Y<br />
</div>
</div>
<div class="main">
<h2>B</h2>
<div class="route">
Z<br />
</div>
</div>
Inside each main, there's more elements beside title and route so I'm looking for a scalable solution. Classes in main are always the same.
I would like to get a tibble that looks like:
id | title | route
1 | A | X
1 | A | Y
2 | B | Z
My current try gives me error because there's a different number of rows in title and route. I also don't know how to index class main.
tibble(
title = html_doc %>% html_nodes("h2") %>% html_text(),
route = html_doc %>% html_nodes(".route") %>% html_text()
)