Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 根据两个条件查找xpath元素_Html_Xml_Xpath - Fatal编程技术网

Html 根据两个条件查找xpath元素

Html 根据两个条件查找xpath元素,html,xml,xpath,Html,Xml,Xpath,我希望能够得到一个XPATH表达式,该表达式返回满足两个条件的行的第二列的链接: 第三列包含toDisk\u/proc/timer\u stats 第四列包含to临界条件 XML是: <tbody> <tr id="table2-0" style="" class="datos2"> <td id="table2-0-0" style="" class="datos2 "></td> <td id="table2-0-1" style="

我希望能够得到一个XPATH表达式,该表达式返回满足两个条件的行的第二列的链接:

  • 第三列包含to
    Disk\u/proc/timer\u stats
  • 第四列包含to
    临界条件
  • XML是:

    <tbody>
    <tr id="table2-0" style="" class="datos2">
    <td id="table2-0-0" style=""   class="datos2 "></td>
    <td id="table2-0-1" style=""   class="datos2 "><a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&refr=0&filter=all_enabled&filter_standby=all&ag_group=0&tag_filter=0&action_filter=0&id_agente=1&tab=alert&amp;id_alert=1&amp;force_execution=1&refr=60"><img src="http://192.168.50.50:84/pandora_console/images/target.png" data-title="Force" data-use_title_for_force_title="1" class="forced_title" style="border:0px;" alt="Force" /></a></td>
    <td id="table2-0-2" style=""   class="datos2 "><span style="font-size: 7.2pt">AvailableMemory</span></td>
    <td id="table2-0-3" style=""   class="datos2 "><a class="template_details" href="ajax.php?page=godmode/alerts/alert_templates&get_template_tooltip=1&id_template=1"><img src="http://192.168.50.50:84/pandora_console/images/zoom.png" /></a> <span style="font-size: 7.1pt">Critical condition</span></td>
    <td id="table2-0-4" style=""   class="datos2 ">Mail&#x20;to&#x20;Admin <i>(Default)</i></td>
    <td id="table2-0-5" style=""   class="datos2 "><span title="Unknown/Never" style="white-space:nowrap;">Unknown</span></td>
    <td id="table2-0-6" style=" text-align:center; width:5%;"   class="datos2 "><img src="http://192.168.50.50:84/pandora_console/images/status_sets/default/alert_not_fired.png" data-title="Alert not fired" data-use_title_for_force_title="1" class="forced_title" alt="Alert not fired" /></td>
    <td id="table2-0-7" style=" text-align:center; width:5%;"   class="datos2 "><input name="validate[]" type="checkbox" value="1"  id="checkbox-validate"  />
    <input id="hidden-validate[]_sent" name="validate[]_sent" type="hidden"  value="1" /></td>
    </tr>
    <tr id="table2-1" style="" class="datos">
    <td id="table2-1-0" style=""   class="datos "></td>
    <td id="table2-1-1" style=""   class="datos "><a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&refr=0&filter=all_enabled&filter_standby=all&ag_group=0&tag_filter=0&action_filter=0&id_agente=1&tab=alert&amp;id_alert=2&amp;force_execution=1&refr=60"><img src="http://192.168.50.50:84/pandora_console/images/target.png" data-title="Force" data-use_title_for_force_title="1" class="forced_title" style="border:0px;" alt="Force" /></a></td>
    <td id="table2-1-2" style=""   class="datos "><span style="font-size: 7.2pt">Disk_/proc/timer_stats</span></td>
    <td id="table2-1-3" style=""   class="datos "><a class="template_details" href="ajax.php?page=godmode/alerts/alert_templates&get_template_tooltip=1&id_template=1"><img src="http://192.168.50.50:84/pandora_console/images/zoom.png" /></a> <span style="font-size: 7.1pt">Critical condition</span></td>
    <td id="table2-1-4" style=""   class="datos ">Mail&#x20;to&#x20;Admin <i>(Default)</i></td>
    <td id="table2-1-5" style=""   class="datos "><span title="Unknown/Never" style="white-space:nowrap;">Unknown</span></td>
    <td id="table2-1-6" style=" text-align:center; width:5%;"   class="datos "><img src="http://192.168.50.50:84/pandora_console/images/status_sets/default/alert_not_fired.png" data-title="Alert not fired" data-use_title_for_force_title="1" class="forced_title" alt="Alert not fired" /></td>
    <td id="table2-1-7" style=" text-align:center; width:5%;"   class="datos "><input name="validate[]" type="checkbox" value="2"  id="checkbox-validate1"  />
    <input id="hidden-validate[]_sent" name="validate[]_sent" type="hidden"  value="1" /></td>
    </tr>
    </tbody>
    
    
    有效记忆
    临界条件
    邮寄 ;至 ;管理员(默认)
    不为人知
    磁盘\进程/计时器\统计信息
    临界条件
    邮寄 ;至 ;管理员(默认)
    不为人知
    
    我希望得到的是:

    • /tbody/tr
      选择根
      tbody
      的子级,其中:
    • td[3]=“Disk\uu/proc/timer\u stats”
      第三列包含文本
      Disk\uu/proc/timer\u stats
    • 规范化空格(td[4])
      第四列的文本内容,忽略前导空格和尾随空格
    • =
      等于
    • “临界条件”
    • /td[2]/a
      然后选择第二列的链接
    • /tbody/tr
      选择根
      tbody
      的子级,其中:
    • td[3]=“Disk\uu/proc/timer\u stats”
      第三列包含文本
      Disk\uu/proc/timer\u stats
    • 规范化空格(td[4])
      第四列的文本内容,忽略前导空格和尾随空格
    • =
      等于
    • “临界条件”
    • /td[2]/a
      然后选择第二列的链接
      • 多亏了,我才能够得到XPATH表达式:

        '//tr[td[3][contains(.,"Disk_/proc/timer_stats")] and td[4][contains(.,"Critical condition")]]/td[2]/a'
        
        返回

        [<a href=​"index.php?sec=estado&sec2=operation/​agentes/​ver_agente&refr=0&filter=all_…action_filter=0&id_agente=1&tab=alert&id_alert=1&force_execution=1&refr=60">​…​</a>​]
        
        [​]
        
        多亏了,我才能够得到XPATH表达式:

        '//tr[td[3][contains(.,"Disk_/proc/timer_stats")] and td[4][contains(.,"Critical condition")]]/td[2]/a'
        
        返回

        [<a href=​"index.php?sec=estado&sec2=operation/​agentes/​ver_agente&refr=0&filter=all_…action_filter=0&id_agente=1&tab=alert&id_alert=1&force_execution=1&refr=60">​…​</a>​]
        
        [​]
        
        您的XPath以何种方式改进了Keith Hall提供的XPath,足以保证单独的答案,而不仅仅是接受他的答案?因为他的表达式在提供的示例中不起作用,所以我获得了语法并创建了自己的XPath。Keith Hall的XPath与提供的示例配合使用。显然,您需要调整如果您的实际示例在非根上下文中使用了
        tbody
        的定位器,但您所做的其他更改实际上可能不是改进:具体地说,使用
        contains()
        而不是像Keith那样的平等可能会导致意外的过度概括。您的XPath以何种方式改进了Keith Hall提供的XPath,足以保证一个单独的答案,而不仅仅是接受他的答案?因为他的表达式在提供的示例中不起作用,所以我获得了语法并创建了自己的。Keith Halls XPath确实适用于提供的示例。显然,如果您的真实示例在非根上下文中使用了
        tbody
        ,您需要调整定位器,但您所做的其他更改实际上可能不是改进:具体地说,使用
        contains()
        而不是像Keith那样的平等可能会导致意外的过度概括。