Session Ready
Exercise

Scraping names

You might have noticed in the previous exercise, to select elements with a certain class, you add a . in front of the class name. If you need to select an element based on its id, you add a # in front of the id name.

For example if this element was inside your HTML document:

<h1 class = "heading" id = "intro">
  Introduction
</h1>

You could select it by its class using the CSS selector ".heading", or by its id using the CSS selector "#intro".

Once you've selected an element with a CSS selector, you can get the element tag name just like you did with XPATH selectors, with html_name(). Try it!

Instructions
100 XP
  • The infobox you extracted in Chapter 4 has the class infobox. Use html_nodes() and the appropriate CSS selector to extract the infobox element to infobox_element.
  • Use html_name() to extract the tag name of infobox_element and store it in element_name.
  • Print element_name.