Session Ready
Exercise

Select by class and ID with XPATH

Here's some HTML code that is similar to code you encountered in the last chapter (already read into an HTML document called weather_html):

<html>
  <body>
    <div id = 'first'>
      <h1 class = 'big'>Berlin Weather Station</h1>
      <p class = 'first'>Temperature: 20°C</p>
      <p class = 'second'>Humidity: 45%</p>
    </div>
    <div id = 'second'>...</div>
    <div id = 'third'>
      <p class = 'first'>Sunshine: 5hrs</p>
      <p class = 'second'>Precipitation: 0mm</p>
    </div>
  </body>
</html>

For this chapter, this code looks a bit more like real life. Your goal is to extract the precipitation reading from this weather station. Unfortunately, it can't be directly referenced through an ID.

Let's do this by setting up the building blocks step by step and then using them in combination!

Instructions 1/4
undefined XP
  • 1
    • In order to warm up, start by selecting all p tags in the above HTML using XPATH.
    • 2
      • Now select only the p elements with class second.
    • 3
      • Now select all p elements that are children of the element with ID third.
    • 4
      • Now select only the p element with class second that is a direct child of #third, again using XPATH.