apple <...">

Xpath: how to not match the following data

Browsing the source, I have table data formatted exactly like this:

<tr class="even"> <td>apple</td> <td>pear</td> <td>orange</td> </tr> <tr class="odd"> <td>apple</td> <td>pear</td> <td>&nbsp</TD> </tr> <tr class="even"> <td>apple</td> <td>pear</td> <td>orange</td> </tr> 

How would I go without matching the <td> containing & nbsp in all lines where this happens?

+4
source share
1 answer

Entity &nbsp; not what XPath knows - it's best to use its equivalent (self- &#xA0; ) symbol object &#xA0;

To select all td top element - table , which do not contain &nbsp; use :

  /table/tr/td[not(contains(., '&#xA0;'))] 

To select all rows in this table so that none of their children td contain &nbsp; use :

  /table/tr[not(td[contains(., '&#xA0;')])] 

To select all td children of all rows in this table so that none of their children td contain &nbsp; use :

  /table/tr[not(td[contains(., '&#xA0;')])]/td 
+5
source

Source: https://habr.com/ru/post/1337634/


All Articles