retrieve data from a class inside another class
-
27-10-2019 - |
문제
I have the following html code
<span class="tag" style="font-size: 12px;"><a href="/tag/Black+Library" target="_top">Black Library</a><span class="count"> (1)</span> </span>
and i want to retrieve number "(1)" from class count inside class tag... how can i do that with jsoup?
code like
Elements num = document.select(".tag count");
is not working.
In fact i want both the "tag" Black Library and the "count" 1.. Any help to do that?
PS. there is another class count, for which the html code is
<li class="gap"><a href="/work/9767358/reviews/78536487">Reviews</a> <span class="count">(0)</span></li>
but i dont want that result.
해결책
Elements num = document.select(".tag count");
This will select elements with class="tag"
attribute and then it will in its children look for <count>
elements. But you actually want to look for elements with class="count"
attribute. Fix the CSS selector accordingly:
Elements num = document.select(".tag .count");
See also:
제휴하지 않습니다 StackOverflow