All Level Text
This exercise is similar to the previous, but differs in that you will be selecting text from multiple generations of a given element.
You will write an XPath and CSS Locator strings 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 includes all text within the future generations. We have created a function print_results for you to compare which elements your strings direct to.
Bu egzersiz
Web Scraping in Python
kursunun bir parçasıdırEgzersiz talimatları
- Assign to the variable
xpathan XPath string directing to the text within the paragraphpelement withidequal top3, which includes the text of future generations of thispelement. - Assign to the variable
css_locatora CSS Locator string directing to this same text.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# 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 )