XPath query to identify unlabeled text

Consider this HTML:

<html>
  <head>
  </head>
<body>
  <table>
    <tr>
      <td>
        <h1>title</h1>
        <h3>item 1</h3>
          text details for item 1
        <h3>item 2</h3>
          text details for item 2
        <h3>item 3</h3>
          text details for item 3
      </td>
    </tr>
  </table>
</body>
</html>

I am not very familiar with XPath, but it seems to me that there is no notation that will correspond to the sections "text details" separately. Can you confirm?

+3
source share
2 answers

Using

/html/body/table/tr/td/h3/following-sibling::text()[1]

This means: Get the first following sibling node text of each element h3, which is a child of each element tr, which is a child of each element table, which is a descendant of each bodyelement, which is a child of the top element html.

, , h3 docunent, XPath :

//h3/following-sibling::text()[1]
+2

Xml/Xpath

- Node.

TD 7

TD.getChild(3) "text details for item 1".

XPath $ x//table/tr/td/text() [1]

+1

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


All Articles