Read a few SO threads on this but I haven't found a great answer (and one may not exist) so I thought I'd try again.
I'm trying to use Selenium with Python to retrieve text from an element, but I want to ignore some child elements within that element. The HTML looks something like this:
<div class="topclass">
<div class="textclass"> Here is some text
<a class="link1"> with a link here </a>
<a class="link2"> and another link here. </a>
and more text.
</div>
</div>
What I need is to retrieve the text "Here is some text and more text" where I ignore the text of the two child link nodes. A couple restrictions:
- The link nodes can be anywhere within the text and there can be any number of them.
- I want to avoid the "get all the text and then parse it within Python" solution if possible (which has been suggested).
- There's nothing unique about the example text here so the solution has to be general to all types of text and can't be coded to the text content itself.
Is there a way to do what I need with Selenium/Xpath?