[英]Jsoup select excluding Elements with :not, not getting expected text
我正在尝试获取不在跨度或_21ok _50f5
类中的所有文本,在这种情况下,我根本不想获取任何文本,但是我一直在获取文本。
我尝试了select(._42ef:not(._21ok._50f5))
和select(._42ef).not(._21ok._50f5)
以及其他所有组合,但仍得到了文本。
<div class="_42ef">
<div class="_6a _5u5j">
<div class="_6a _6b" style="height:36px"></div>
<div class="_6a _5u5j _6b">
<div class="">
<span class="_21ok _50f5">Add your current city</span>
<span class="img _55ym _55yn _55yo _5tqs _3-9a" aria-label="Loading..." aria-busy="1"></span>
</div>
</div>
</div>
</div>
任何人都知道问题是什么或如何解决?
我认为有几个原因导致它无法达到您希望的效果。 这是一些有效的javascript / jquery的示例。 希望对您有所帮助:
//Look in all elements of your root and specify each filter criteria separately
$('._42ef').find('*').not('span, ._21ok, ._50f5').each(function() {
//Only get immediate text
var directText = $(this).clone()
.children()
.remove()
.end()
.text().trim();
//Only add if text has value (and is not just whitespace)
if (directText) texts.push(directText);
});
我还准备了一个jsfiddle来帮助: https ://jsfiddle.net/038o91ec/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.