我正在尝试匹配文本,并在xpath中输出包括self在内的整个行。
我遇到的问题是self节点在html表中也包含javascript,并且它也在输出脚本。
我尝试了以下方法:
正在工作,但包含来自自身节点的javascript:
$bo_row = $bo_xpath->query( "//td[contains(text(),'1234')]/following-sibling::* | //td[contains(text(),'1234')] " );
失败的尝试都类似于:
$bo_row = $bo_xpath->query( "//td[contains(text(),'1234')]/following-sibling::* | //td[contains(text(),'1234')]//*[not(self::script)] " );
以下是一个表格行的示例:
<tr>
<!-- <td><a class=info href="**Missing Data**">
<img src="../images/button_go.gif" border=0>
<span>**Missing Data**</span>
</a>
</td> -->
<script>
if (document.getElementById("Function").value != 'Customer')
document.write('<td><a class=info href="OrdDetLine.pgm?Order=CV780&Page=02&Line=05&Seq=00&ShowPrice=&OpenOnly=&Function=Customer"><img src="../images/button_go.gif" border=0><span>Order Line Detail</span></a></td>');</script>
<td align="left">2-05-00</td>
<td align="left"> 1234
<script>if (document.getElementById("Function").value != 'Customer')
document.write("<a class=info href=#><img src=/operations/images/eye.png border=none onClick=window.open(\'StyleHdr.pgm?CompDiv=CO&Style=1234\'><span>Show style master information panel.</span></a>") ; </script>
</td>
<td align="left">MEN'S LAB/SHOP COATS</td>
<td align="left">REG</td>
<td align="left">NAY</td>
<td align="right">1</td>
<td align="right">April 12, 2019</td>
</tr>
我尝试使用getAttribute选择内部文本,如下所示:
$ bo_row = $ bo_xpath-> query(“ // tr / td [contains(text(),'1234')] / following-sibling :: * | // td [contains(text(),'1234 ')]“);
echo '<br/>';
if ( $bo_row->length > 0 ) {
foreach ( $bo_row as $row ) {
echo $row->getAttribute ('innerText');
}
但是我要么正确使用了getAttribute,要么不像PHPstorm所指示的那样使用php