Not every sibling is the same
In the video, you got to know the adjacent and general sibling combinator (+ and ~).
The following HTML code contains two headings followed by some code and span tags:
<html>
<body>
<h2 class = 'first'>First example:</h2>
<code>some = code(2)</code>
<span>will compile to...</span>
<code>some = more_code()</code>
<h2 class = 'second'>Second example:</h2>
<code>another = code(3)</code>
<span>will compile to...</span>
<code>another = more_code()</code>
</body>
</html>
Note that the two code examples here are not hierarchically organized. The only obvious difference is the class of the h2 element that precedes each example.
This HTML chunk has been read in for you and is available in the code_html variable.
Latihan ini adalah bagian dari kursus
Web Scraping in R
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Select only the first code element in the second example
code_html %>%
___('h2.second ___ ___')