XPath - 体内的所有元素

3zz*_*zzy 3 html php xpath

我一直在使用这个查询:

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

..但它也从非必需元素(<head>等..)中获取内容,因此我想将搜索限制在 中<body>,但这由于某种原因不起作用:

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

...对于此 HTML: http: //pastebin.com/F4xVDL8Q

har*_*r07 8

XPath 的以下部分指示应仅在 的直接子元素中进行搜索body

//body/*
Run Code Online (Sandbox Code Playgroud)

body由于您的意思是搜索then中的所有元素,//*因此应该使用:

//body//*[...]/text()[...][string-length() > 140]
Run Code Online (Sandbox Code Playgroud)