简体   繁体   English

XPath-体内的所有元素

[英]XPath - all elements inside body

I've been using this query: 我一直在使用此查询:

//*[self::div or self::p or self::span]/text()[normalize-space()][string-length() > 140]

.. but it also fetches content from the non-required elements ( <head> etc..) so I want to restrict the search within <body> , but this doesn't work for some reason: ..但它也从不需要的元素( <head>等)中获取内容,因此我想将搜索限制在<body> ,但这由于某些原因而无法使用:

//body/*[self::div or self::p or self::span]/text()[normalize-space()][string-length() > 140]

... for this HTML: http://pastebin.com/F4xVDL8Q ...针对此HTML: http//pastebin.com/F4xVDL8Q

The following part of your XPath indicate that the search should be done only in direct child elements of body : XPath的以下部分指示,仅应在body 直接子元素中进行搜索:

//body/*

Since you mean to search in all elements within body then //* should've been used instead : 由于您要搜索body中的所有元素,因此应该使用//*代替:

//body//*[...]/text()[...][string-length() > 140]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM