我希望在以下HTML结构的“2014 Spring Recreation Soccer”文本的基础上使用Xpath找到“U10 Boys”文本:
<?php
if(isset($_GET['jid']))
{
$jid=$_GET['jid'];
$status=$_GET['status'];
if($status=='active') { $new_status='inactive'; } else { $new_status='active'; }
$delet_query = mysql_query("UPDATE job SET status='$new_status' WHERE jid='". $jid."' ") or die(mysql_error());
if($delet_query) {
echo 'job with id '.$row[jid].' is activated, to refresh your page, click'. '<a href='.$_SERVER["PHP_SELF"].' > here </a>';
}
}
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>JOb ID</th>
<th>CompanyID</th>
<th>Job Description</th>
<th>Duration</th>
<th>Budget</th>
<th>KeySkills</th>
<th>Joining Date</th>
<th>Expiry Date</th>
<th>Min Experience</th>
<th>Max Experience</th>
<th>Status</th>
<th>Set Status</th>
</tr>
</thead>
<tbody>
<?php
$res=mysql_query("SELECT * FROM job ORDER BY jid DESC");
while($row=mysql_fetch_array($res))
{
?>
<tr>
<td><p><?php echo $row['jid']; ?></p></td>
<td><p><?php echo $row['cid']; ?></p></td>
<td><p><?php echo $row['jdesc']; ?></p></td>
<td><p><?php echo $row['duration']; ?></p></td>
<td><p><?php echo $row['budget']; ?></p></td>
<td><p><?php echo $row['keyskills']; ?></p></td>
<td><p><?php echo $row['jdate']; ?></p></td>
<td><p><?php echo $row['edate']; ?></p></td>
<td><p><?php echo $row['cdexmin']; ?></p></td>
<td><p><?php echo $row['cdexmax']; ?></p></td>
<td><p><?php if($row['status']=="active") { echo "Active"; } else { echo "Inactive"; } ?></p></td>
<td><a href="?jid=<?php echo $row['jid']; ?>&status=<?php echo $row['status']; ?>"><?php if($row['status']=="active") { echo "Activate"; } else { echo "DeActivate"; } ?></a></td></tr>
<?php } ?>
</tbody>
</table>
我试过跟随Xpath,但它不起作用。
<div>
<div>
<table>
<thead>
<tr>
<td>
<table>
<tbody>
<tr>
<td > </td>
<td >
<span>2014 Spring Recreation Soccer</span>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</thead>
</table>
</div>
<div>
<table >
<tbody>
<tr >
<td >1</td>
<td >
<b>
<span >U10 Boys</span>
</b>
</td>
</tr>
</tbody>
</table>
</div>
</div>
答案 0 :(得分:2)
您可以尝试这种方式:
//div[table[contains(., "2014 Spring Recreation Soccer")]/following-sibling::div[1]//span[contains(.,"U10 Boys")]
解释:
//div[table[contains(., "2014 Spring Recreation Soccer")]
:在文档中的任意位置找到div
元素,其中子元素table
包含文字"2014 Spring Recreation Soccer"
/following-sibling::div[1]
:从div
开始,导航到最近的兄弟div
...
//span[contains(.,"U10 Boys")]
:...并在兄弟span
"U10 Boys"
的{{1}}元素