Select the last child with a pseudo-class
In the following HTML showing the author of a text in the last paragraph, there are two groups of p
nodes:
<html>
<body>
<div>
<p class = 'text'>A sophisticated text [...]</p>
<p class = 'text'>Another paragraph following [...]</p>
<p class = 'text'>Author: T.G.</p>
</div>
<p>Copyright: DC</p>
</body>
</html>
In this exercise, your job is to select the last p
node within the div
.
As you learned in the video, pseudo-classes can help you whenever you don't have other means of selecting a specific node of page, e.g., through an ID selector or a unique class.
The above HTML document is provided to you through the nested_html
variable (already read in via read_html()
).
This exercise is part of the course
Web Scraping in R
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Select the last child of each p group
nested_html %>%
___