简体   繁体   中英

Jsoup printing each <div> content in a separate line

I have been working on a web link with java jsoup library to extract some parts of it.

This is the part which I work on it.

<div class="adv_side_price">
  100,000 ريال 
</div>
<div class="adv_side_price">
  16,000 ريال 
</div>
<div class="adv_side_price">
  16,000 ريال 
</div>
<div class="adv_side_price">
  16,000 ريال 
</div>
<div class="adv_side_price">
  37,000 ريال 
</div>
<div class="adv_side_price">
  150,000 ريال 
</div>
<div class="adv_side_price">
  60,000 ريال 
</div>
<div class="adv_side_price">
  119,000 ريال 
</div>

The output should be as following:

100,000

19,500

37,000

150,000

60,000

119,000

10,000

I used the following code

 Document doc = Jsoup.connect("https://www.bezaat.com/ksa/riyadh/cars/all/1").get();
 System.out.println("Price"+doc.select("div.adv_side_price").text().replace("ريال","")); 

But output gained as one line

Price 100,000  19,500  37,000  150,000  60,000  119,000  10,000 

Could someone possibly helps please

Try printing content of each div using separate println call like

Document doc = Jsoup.connect("https://www.bezaat.com/ksa/riyadh/cars/all/1").get();
for (Element el : doc.select("div.adv_side_price"))
    System.out.println(el.text().replace("ريال", ""));

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