X
X
xaiponews2020-12-11 02:13:34
Android
xaiponews, 2020-12-11 02:13:34

How to pass same content from same HTML attributes using Jsoup?

I am new to programming, please help.
There is a parsed web page, part of the code looks like this:

Elements elements = doc.getElementsByClass("ClassName");
elements content:

<div class="ClassName01"> Text01 </div> 
<a class="ClassName02" href="URL.q01" title="Text02"> <i class="iconA"></i> <span>Text03</span> </a></div>
<a href="URL.p01" class="ClassName03" data-user="111"> <img class="ClassName04" width="30" height="30" alt="Text04" src="URL"> </a>
<a href="URL.q02" class="ClassName05">Text05</a>
<div class="ClassName06"> <a href="URL.p01" class="ClasName07">Text06</a>


I need to pull only the contents of "URL.q02" from the class "ClassName05".
I have tried:
1) String string = elements.select("a").attr("href"); - passes all values ​​after "(href= ...)"
2) String string = elements.select("a.ClassName05").attr("href"); - finds nothing.
3) String string = elements.select("ClassName05").select("a").attr("href"); - finds nothing.
Tell me what variable you need to specify so that Jsoup passes only the required object.

Parsing deeper is a working option, but not suitable, since there is a lot of additional code to write. I'm looking for an easier option, maybe I haven't tried everything.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xaiponews, 2020-12-12
@xaiponews

Maybe it will be useful for someone, here is the answer. The code should look like this:
String string = elements.select("a[ClassName05]").attr("href")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question