Session Ready
Exercise

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()).

Instructions 1/2
undefined XP
  • 1
    • In a first attempt, use the pseudo-class that selects the last child to scrape the last p in each group.
    • 2
      • As this selected the last p node from both groups, make use of the text class to get only the authorship information.