Get startedGet started for free

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.

This exercise is part of the course

Web Scraping in R

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Select only the first code element in the second example
code_html %>% 
	___('h2.second ___ ___')
Edit and Run Code