Top Level Text
This exercise will have you write an XPath and CSS Locator string to direct to the text of a specific paragraph p element. The p element in the HTML is uniquely defined by its id attribute, which is "p3". With this small piece of information, you should be able to create the desired strings; however, we have preloaded the variable html with a string containing the HTML in which this link belongs, if you want to peruse it.
In this exercise, you will only be selecting the text within the element, which does not include the text in future generations of the element. We have created a function print_results for you to compare which elements your strings direct to.
Deze oefening maakt deel uit van de cursus
Web Scraping in Python
Oefeninstructies
- Assign to the variable
xpathan XPath string directing to the text within the paragraphpelement withidequal top3, which does not include the text of future generations of thispelement. - Assign to the variable
css_locatora CSS Locator string directing to this same text.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Create an XPath string to the desired text.
xpath = ____
# Create a CSS Locator string to the desired text.
css_locator = ____
# Print the text from our selections
print_results( xpath, css_locator )