A classy span
Although we haven't yet gone deep into XPath, one thing we can do is select elements by their attributes using an XPath. For example, if we want to direct to the div element within the HTML document whose id attribute is "uid", then we could write the XPath string '//div[@id="uid"]'. The first part of this string, //div, first looks at all div elements in the HTML document. Then, using the brackets, we specify that we want only the div element with a specific id attribute (in this case uid). To note, the phrase @id="uid" in the brackets would be read as "attribute id equals uid".
In this exercise, you will select all span elements whose class attribute equals "span-class". (Note: span is just another possible tag-name).
Deze oefening maakt deel uit van de cursus
Web Scraping in Python
Oefeninstructies
- Assign to the variable
xpathan XPath string which will select allspanelements whose class attribute equals"span-class". You do not need to see the actual HTML code to do this!
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Fill in the blank
xpath = ____