The (X)Path to CSS Locators
Many people prefer using CSS Locator notation to XPath notation. As we will see later, it often makes attribute selection very easy. To help get you more comfortable going back and forth between XPath and CSS Locator strings, we give you a chance in this exercise to do some direct "translation" between the two.
Note that the exercises in this chapter may take some time to load.
This exercise is part of the course
Web Scraping in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create the XPath string equivalent to the CSS Locator
xpath = '/html/body/span[1]//a'
# Create the CSS Locator string equivalent to the XPath
css_locator = ____