Anand
Anand

Reputation: 1939

Use XPath to scrape elements which do not contain a certain child element

For a scraper I am looking to get a list of all elements on a page, which do not contain a certain child element. The DOM looks something like this

<scrape>
      <div id='123'>
          <span>test</span>
      </div>
</scrape>
<scrape>
      <div id='1234'>
          <span>test</span>
      </div>
</scrape>
<scrape>
      <div id='12345'>
          <span>test</span>
          <span>don't include</span>
      </div>
</scrape>

What I need to do is, my list needs to contain all scrape elements which do not contain a span with text don't include.

Any ideas?

Thanks!

Upvotes: 3

Views: 186

Answers (1)

Prophet
Prophet

Reputation: 33351

This should work

//scrape[not(.//span[text()='don't include'])]

Literally:
Element(s) with tag name scrape not having inside it (child element) with span tag name and text with value don't include

Upvotes: 2

Related Questions