在 xpath 中提取同级元素 [英] extracting just-sibling element in xpath

查看:53
本文介绍了在 xpath 中提取同级元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这行代码来选择这个元素

I am using this line of code to select this element

x=temp_tree.xpath('//font[text()="放入经度:"]/just-sibling::td/font/text()')

x=temp_tree.xpath('//font[text()="Put In Longitude : "]/just-sibling::td/font/text()')

这是一个错误.请更正.

It is giving an error. Please Correct it.

推荐答案

>>> thingy = tree.xpath('..//font[text()="Put In Latitude : "]/../following-sibling::td/font/text()')
>>> thingy
['47.8034515']

您选择的字体没有兄弟字体.使用 .. 返回树上的父 td,然后向下查找包含所需项目的兄弟 td.

The font you selected doesn't have a sibling. Go back up the tree to the parent td with .. and then down to find the sibling td containing the required item.

这篇关于在 xpath 中提取同级元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆