简体   繁体   中英

Jsoup parsing from String

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:janberg37@Caiway.nl">janberg37@Caiway.nl</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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM