I’ve a html file and want to locate the table(among many) with second TH content of “Stn Code” and 3rd TH content of “Route No.”. What will be the XPATH expression in php to get this particular table:
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr class="heading_table_top">
<th width="6%">SNo</th>
<th width="9%">Stn Code</th>
<th width="17%">Stn Name</th>
<th width="9%">Route No.</th>
<th width="9%">Arrival Time</th>
<th width="9%">Dep. Time</th>
<th width="15%">Halt Time (In Minutes)</th>
<th width="9%">Distance</th>
<th width="6%">Day</th>
<th width="20%">Remark</th>
…………………………….
This will find the table with the specified content regardless of which
ththe content contains:demo
If you want to make sure the content is in specific
thelements, useth[n]wherenis the position, e.g. for the “second TH content of “Stn Code” and 3rd TH content of “Route No.”. you’d useth[2]andth[3]. Positions are 1-based.Note that in your example markup “Route No.” is in
th[4]so the above XPath will not produce the table in the result nodes.Also have a look at this XPath tutorial.