gettext - How to selecting text outisude div with Jsoup -


here's problem, have html code this.

<div class="article">      "some text on here"       <div class="ads">             "ads text on here"       </div> <div> 

what i'm trying is, want text div class="artikel".

for now, try jsoup code.

doc.select("div[class=article]").text(); 

but got code

"some text on here ads text on here"

what want

"some text on here"

is there can me text use jsoup's css selector ?

i don't want use string library.

thanks.

you can use owntext() exclude containing tag elements of selected element :

doc.select("div.article").first().owntext(); 

also , depending on requirement , may interested in textnodes() :

for example, input html:  <p>one <span>two</span> 3 <br> four</p> p element selected:  p.text() = "one 2 3 four" p.owntext() = "one 3 four" p.children() = elements[<span>, <br>] p.childnodes() = list<node>["one ", <span>, " 3 ", <br>, " four"] p.textnodes() = list<textnode>["one ", " 3 ", " four"] 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -