我一直在使用这个查询:
//*[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
XPath 的以下部分指示应仅在 的直接子元素中进行搜索body
:
//body/*
Run Code Online (Sandbox Code Playgroud)
body
由于您的意思是搜索then中的所有元素,//*
因此应该使用:
//body//*[...]/text()[...][string-length() > 140]
Run Code Online (Sandbox Code Playgroud)