首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用xpath获得第二个最后一个值?

如何使用xpath获得第二个最后一个值?
EN

Stack Overflow用户
提问于 2017-05-05 10:04:27
回答 1查看 2.2K关注 0票数 3

是否可以使用xpath获得第二个最后一个元素,即"778-893-3551“,而不对表达式末尾的任何数字进行硬编码?我试过:

代码语言:javascript
运行
复制
//section[@id="postingbody"]/text()

我不想用这样的东西

代码语言:javascript
运行
复制
//section[@id="postingbody"]/text()[2]

因为,如果任何项丢失或项与其编号不同,则表达式末尾使用的序列号不会带来任何结果。

下列值的元素:

代码语言:javascript
运行
复制
<section id="postingbody">Located in the heart of Guildford. Surrey, Built in 2014, looks and feels new. No GST. Still under 2/5/10 National New Home Warranty. Timeless Craftsman-style architecture, with wood and hardy plank exterior. Open floor plan with 9' ceiling on the main floor. 30" ceran top electric range self-cleaning oven and stainless steel 3 door fridge. Contemporary Real Maple cabinets. 2 Storey clubhouse with Gym, Sauna, Party hall &amp; Guest Suite. Easy access to No. walking distance to Guildford mall, library and all the services you desire, very convenient location, 8 minutes drive to a skytrain station, 2 minutes drive to hwy 1.<br>
2 covered parking.<br>
10 minutes drive from Coquitlam Centre.<br>
<br>
Call to make an appointment to view the place.<br>
<br>
Ahmed Afandi<br>
778-893-3551<br>
Kore Realty Central</section>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-05 10:16:06

可以将选定元素的位置设置为last-1

代码语言:javascript
运行
复制
//section[@id="postingbody"]/text()[position()=last()-1]
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43802102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档