0

I am new with using Jsoup and i have a problem to get the text value from div with class name text as a string. This is the string that a want to scrap.

<body>
 <div class="details "> 
  <div class="title turquoise2">
    AAC-Olympia 
  </div> 
  <div class="subhead turquoise2">
    Correspondentie-adres: 
  </div> 
  <div class="text">
    Rijdt 37 
   <br /> 6631AP HORSSEN 
   <br /> 0487-541339 
  </div> 
  <div class="subhead turquoise2">
    Accommodatie: 
  </div> 
  <div class="text">
    Sportpark De Polenkamp 
   <br /> Bredestraat 3 
   <br /> 6631BC HORSSEN 
   <br /> 0487-541339 
  </div> 
  <div class="subhead turquoise2">
    Opgericht: 
  </div> 
  <div class="text">
    01-07-2011 
  </div> 
  <div class="subhead turquoise2">
    Tenue: 
  </div> 
  <div class="text">
    Shirt: Wit 
   <br /> Broek: Zwart 
   <br /> Kousen: Zwart 
  </div> 
  <div class="subhead turquoise2">
    Regio: 
  </div> 
  <div class="text">
    Veldregio: Regio 4 veld 
   <br /> Zaalregio: 
  </div> 
  <div class="subhead turquoise2">
    Info: 
  </div> 
  <div class="text">
    Relatienummer: NXTG36Z 
   <br /> Email: 
   <a href="mailto:[email protected]">[email protected]</a> 
   <br /> Website: 
   <a href="http://www.aac-olympia.nl">http://www.aac-olympia.nl</a> 
   <br /> District: Oost 
  </div> 
  <div class="subhead turquoise2">
    Klasse(s): 
  </div> 
  <div class="text">
    Klasse za: 
   <br /> Klasse zon: 5e klasse 
   <br /> Klasse zaal: 
   <br /> Junioren: Nee 
   <br /> Pupillen: Nee 
   <br /> Vrouwen: Nee 
   <br /> G-Voetbal: Nee 
  </div> 
  <div class="text"> 
   <a href="http://downloadcentrum.knvb.nl/sportlink/knvb/document/matrix%20verenigingen%20district%20oost?id=55988">Overzicht indeling district Oost</a> 
  </div> 
 </div> 
 <div class="details details-functionaris"> 
  <div class="title turquoise2">
    AAC-Olympia 
  </div> 
  <div class="voorzitter"> 
  </div> 
  <div class="secretaris"> 
  </div> 
  <div class="penningmeester"> 
  </div> 
  <div class="functionarissen"> 
  </div> 
 </div>
</body> 

I want to get from second div with class name text following information separate, i tried following code but gives me empty string,

Element Adres = finalDocument.getElementsByClass("text").get(1);
 String AllTextValue = Adres.text();//This give me all information from the div 

But i want all 4 text value apart,

String firstText =  For this one i have no ieee what i need to do
  String SecondText = Adres.getElementsByTag("br").get(0).text();//Returns Empty value
  String ThirdText  = Adres.getElementsByTag("br").get(1).text();//Returns Empty value
  String FourthText = Adres.getElementsByTag("br").get(2).text();//returns Empty value

Can somebody help me. Thank i lot.

1 Answer 1

1

Elements implements the List interface so just use:

Elements Email = finalDocument.getElementsByTag("a");
String emailAddress = Email.get(0).text();

Naming the Elements object Email is slightly misleading. I would recommend the following refactored code:

Elements anchors = finalDocument.getElementsByTag("a");
String email = anchors.get(0).text();
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much it's work perfect, can i ask you one more think, i'm also try to get second <div class="text"> information, you can also see this file has a lot of div class with attribute value of "text" how to choose which div class that a want to use to get information from this file?
I just did Element Adres = finalDocument.getElementsByClass("text").get(1); and i think this is a good approach to get second div, thank you any way for your help.
Glad I could help. Sorry I got pulled away and didn't see your follow on question. It appears you were able to resolve it using something similar to my answer (using the list). If this solved your issue would you consider accepting?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.