gpt4 book ai didi

xpath - 如何使用 xpath 获取倒数第二个值?

转载 作者:行者123 更新时间:2023-12-03 17:26:30 25 4
gpt4 key购买 nike

是否可以使用 xpath 到达倒数第二个元素,在本例中为“778-893-3551”,而无需在表达式末尾硬编码任何数字?我试过:

//section[@id="postingbody"]/text()

我不想使用这样的东西:

//section[@id="postingbody"]/text()[2]

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

值内的元素:

<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>

最佳答案

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

//section[@id="postingbody"]/text()[position()=last()-1]

关于xpath - 如何使用 xpath 获取倒数第二个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43802102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com