[英]Jsoup select excluding Elements with :not, not getting expected text
I'm trying to get all text that isn't in a span or in class _21ok _50f5
, in this case I want to get no text at all, but I keep getting the text. 我正在尝试获取不在跨度或
_21ok _50f5
类中的所有文本,在这种情况下,我根本不想获取任何文本,但是我一直在获取文本。
I tried all combinations of select(._42ef:not(._21ok._50f5))
, and select(._42ef).not(._21ok._50f5)
and more , but I still get the text. 我尝试了
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>
Anyone knows what the problem is or how to fix it? 任何人都知道问题是什么或如何解决?
I think there were several reasons why this was not performing as you had hoped. 我认为有几个原因导致它无法达到您希望的效果。 Here is an example of some javascript/jquery that works.
这是一些有效的javascript / jquery的示例。 I hope it helps:
希望对您有所帮助:
//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);
});
I also prepared a jsfiddle to help: https://jsfiddle.net/038o91ec/ 我还准备了一个jsfiddle来帮助: https ://jsfiddle.net/038o91ec/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.