美国国务院网站(http://www.state.gov/r/pa/ei/speeches/index.htm)中的日期位置比较特别,如下所示
<br />
<a id="January" name="January" style="text-decoration:none;font-size:11pt;font-weight:bold;color:black">January</a><br />
-01/08/13 <a target="_self" href="http://usun.state.gov/briefing/statements/202589.htm">Remarks at a Stakeout after UN Security Council Consultations on Sudan and South Sudan</a>; U.S. Permanent Representative to the United Nations Susan E. Rice, U.S. Mission to the United Nations; New York, NY<br />
日期“-01/08/13”所在的位置没有任何父节点可以直接访问,因此只能考虑使用其前后节点来定位。
观察后发现其后面的节点是属性target为_self的a节点,因此可以写出定位语句如下:
//div[@id='tier3-landing-content']//a[@target='_self']/preceding-sibling::text()[position()=1]
实验后发现结果理想,上图。

本文介绍了如何在美国国务院网站上定位特定格式的日期,通过分析网页结构,找到了一种有效的方法来定位这些日期,并给出了具体的XPath表达式。

2638

被折叠的 条评论
为什么被折叠?



