[英]Difference between a/img/..//text() and a//text()
I'm working with Scrapy and lxml trees to sort out html trees. 我正在使用Scrapy和lxml树来整理html树。
I noticed that there is difference between these two xpath expressions. 我注意到这两个xpath表达式之间存在差异。 I was under the impression that they were interchangeable.
我的印象是他们可以互换。 Could someone please explain me the difference?
有人可以解释我的区别吗?
response.xpath('/html/body/div/table/tr/td/table/tr/td/table/tr/td/table/tr/td/table/tr/td/a/img/..//text()').extract()
response.xpath('/html/body/div/table/tr/td/table/tr/td/table/tr/td/table/tr/td/table/tr/td/a//text()').extract()
The difference between a/img/..//text()
and a//text()
is that the first will return you text nodes ONLY from a
elements with img
elements as children, whereas the second will return text nodes from a
elements irrespective of whether they have img
elements as children. 之间的区别
a/img/..//text()
和a//text()
是第一个将返回文本节点只能从a
与元素img
元素作为孩子,而第二将从返回文本节点a
元素不论他们是否有img
元素作为孩子。
Put another way, a/img/..//text()
could equally be written a[img]//text()
; 换句话说,
a/img/..//text()
同样可以写成a[img]//text()
; compare this with a//text()
. 将其与
a//text()
进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.