选择第一个<p>标签,任何人都可以告诉下面代码的xpath是什么?

时间:2017-09-27 09:55:02

标签: xpath

<div class="main-banner"><img alt="Health and Safety In Care" height="291px" width="650px" class="img-responsive" height="291px" Width="650px" src="images/Care Safety.jpg" /></div>  

<p>It is a legal requirement that those in the care sector must have sufficient health and safety training to ensure the safety of both staff and patients.</p>
<p>The below range of health and safety courses specialise in handling different equipment and scenarios often encountered in the care sector. Our courses boast accreditation from the CIEH and HABC, and are designed to fulfil recommendations made by the CQC.</p>

  

在包含的<p>标记之后选择xpath的<div>标记   main-banner上课。

<div class="main-banner"><img alt="Health and Safety In Care" height="291px" width="650px" class="img-responsive" height="291px" Width="650px" src="images/Care Safety.jpg" /></div>  

<p>It is a legal requirement that those in the care sector must have sufficient health and safety training to ensure the safety of both staff and patients.</p>
<p>The below range of health and safety courses specialise in handling different equipment and scenarios often encountered in the care sector. Our courses boast accreditation from the CIEH and HABC, and are designed to fulfil recommendations made by the CQC.</p></div>

2 个答案:

答案 0 :(得分:1)

要在<p>节点后面<div>选择 1 st class="main-banner"节点:

(//div[@class="main-banner"]/following-sibling::p)[1]

<强> ----------

如果关键<div>节点在类属性(例如class="cont baseline main-banner")中有多个项目,请使用以下 xpath 表达式:

(//div[contains(@class,"main-banner")]/following-sibling::p)[1]

答案 1 :(得分:0)

xpath:

  //div[@class="main-banner"]/following-sibling::p [1]