I want to get table data by XPath

Asked 2 years ago, Updated 2 years ago, 161 views

I would like to use XPATH to retrieve table data.
The table data is as follows:
"At this time, you can specify ""number of people"" and ""average height"" by entering the following, but I don't know how to get ""5"" and ""170"" underneath them, so I would like to ask you a question."

/table/tr [td [contains (normalize-space(), "average height")]]

*We would like to use the same XPATH for the number of people and average height except within

<table>
  <tr>
    <td>Number of people</td>
    <td>Average Height</td>
  </tr>
  <tr>
    <td>5</td>
    <td>170</td>
  </tr>  
</table>

xpath

2022-09-30 19:35

1 Answers

With XPath 2.0, you can write like this.

for $i in 1 to count(/table/tr[1]/td) return if(contains(/table/tr[1]/td[$i], 'average weight'))then string(/table/tr[2]/td[$i])else()

Run XPath/XQuery Builder on Xygen 20.0 Screen:

Run Screen "src="https://i.stack.imgur.com/6LY35.png"/>

in oXygen 20.0<p>For your information.</p><p>[PS] <br/>I think it's easiest to use <code>index-of</code>For example, </p><div style='background:#eeeeee;border:1px solid #cccccc;padding:5px 10px;'><pre><code>/table/tr[2]/td[index-of(/table/tr[1]/td/string(.), 'average weight']/string(.)]/string(.)</code></pre></div><p><strong>Similar Run Screen: </strong></p><p><a href=Run Screen "src="https://i.stack.imgur.com/ajxk5.png"/>

in

2022-09-30 19:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.