使用xpath获取选择性内容

时间:2014-04-29 12:32:11

标签: xpath

<li>
<a href="http://chem.iitm.ac.in/cihs">Chemistry In-House Symposium 2014 (CiHS-2014) </a>
<br>
In 2011, Chemistry In-House Symposium (CiHS) was initiated as department yearly        event on the occasion of the International Year of Chemistry and Golden Jubilee Year of the Department. The theme of the CiHS is to provide the platform for the deliberation of exciting research findings and mutual exchange of ideas within the Department. This yearly event, in addition, is expected to provide an opportunity for further enhancing the collaborative research within the department. This year, the CiHS will be organized on the Wednesday, August 13, 2014 at IC & SR auditorium, IIT Madras.
<br>
<strong>Venue:</strong>
IC & SR auditorium, IIT Madras
<br>
<strong>Dates:</strong>
Aug 13, 2014 to Aug 13, 2014
<br>
<strong>Coordinator(s):</strong>
Ramesh Gardas
</li>

我需要为上面的脚本编写一个xpath,我应该只能获得&#39; a&#39;标签,日期和地点。我不想要整个描述。有什么方法我们只能使用xpath =&gt;获得选择性文本。 // div [@class =&#39; block-inner clearfix&#39;] / ul / li // text()

1 个答案:

答案 0 :(得分:1)

要获取a元素中的文本,您只需执行

即可
//div[@class='block-inner clearfix']/ul/li/a/text()

要获取紧跟在指定的<strong/>元素之后的文本,您可以使用以下XPath:

//div[@class='block-inner clearfix']/ul/li/text()[preceding-sibling::strong = "Dates:"][1]

要获得场地,请分别使用

//div[@class='block-inner clearfix']/ul/li/text()[preceding-sibling::strong = "Venue:"][1]