VAK5d6
VAK5d6

Reputation: 47

Jsoup to get the price on this website

I wanna get the price 13.490.000 from this page source.

I tried this code but it did't print out anything.

Document doc = Jsoup.connect("http://www.thegioididong.com/dtdd/sony-xperia-z1").get();

Elements spans = doc.select("span[itemprop]");

for (Element span : spans) {
      System.out.println(span.text());
    }

Hope somebody can help !

Upvotes: 1

Views: 488

Answers (2)

Matthew
Matthew

Reputation: 76

It seems to me that one problem that you have is that you are trying to select all of the <span> elements with the attribute itemprop. Try selecting only the <span> element with the attribute itemprop with the value equal to "price".

Document doc = Jsoup.connect("http://www.thegioididong.com/dtdd/sony-xperia-z1").get();
Element span = doc.select("span[itemprop=\"price\"]").first();
System.out.println(span.text());

I put in the .first() because I think that jsoup may need you to state that you are selecting one element only. You may not need this, though.

Upvotes: 0

Aleksei Shestakov
Aleksei Shestakov

Reputation: 2538

I looked at the output of System.out.println(doc.html()); and price is specified in the element with class contentInfoPriceOrder, so you can print it like this:

Elements spans = doc.select(".contentInfoPriceOrder");
for (Element span : spans) {
    System.out.println(span.child(0).text());
}

Upvotes: 1

Related Questions