- Date Created: [[2020-09-10]] - To get the text of an element or node, use `text()` - For example: ```javascript >>> import lxml.etree as ET >>> tree = ET.fromstring('''<div> ... <div> ... <p> ... <span class="abc">Monitor</span> <b>$300</b> ... </p> ... <a href="/add">Add to cart</a> ... </div> ... <div> ... <p> ... <span class="abc">Keyboard</span> $20 ... </p> ... <a href="/add">Add to cart</a> ... </div> ... </div>''') >>> tree.xpath('//div[a[contains(., "Add to cart")]]/p//text()') ['\n ', 'Monitor', ' ', '$300', '\n ', '\n ', 'Keyboard', ' $20 \n '] >>> res = _ >>> [txt for txt in (txt.strip() for txt in res) if txt] ['Monitor', '$300', 'Keyboard', '$20']``` - Source: https://stackoverflow.com/questions/14631590/get-text-content-of-an-html-element-using-xpath - In this example, all descendant elements were selected.