Where am I?
In this exercise, you will navigate to a specific element using your new knowledge of XPath notation.
Consider the HTML code:
<html>
<body>
<div>
<p>Good Luck!</p>
<p>Not here...</p>
</div>
<div>
<p>Where am I?</p>
</div>
</body>
</html>
Your job will be to create an XPath string using single forward-slashes and brackets which navigates to the paragraph p
element which contains the text "Where am I?".
This exercise is part of the course
Web Scraping in Python
Exercise instructions
- Using only single forward-slashes to move between generations, and brackets to select the correct element, assign a string to the variable
xpath
that directs to the paragraph element containing "Where am I?". - Do not include any blank spaces in the string you assign to
xpath
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Fill in the blank
xpath = '/html/body/____'