I suppose there is more to this question. Pisek's logic is correct the class lst-product-item-price
gives the list of all prices, but it gives only the list in one page. In this case we have 27 pages. Also it has different sorting order. So you might have to navigate through all the pages and then find the cheapest.
However, I was wondering why do we need a parsing to the html here? The URL in question is http://www.mimovrste.com/letne-avtomobilske-pnevmatike?p-min=31.65&p-max=348.35&o=_price
. This itself says the minimum and maximum price. So the result could be parsed right away from the URL string.
Suppose you need a the result from an unfiltered list, that is you need to find the cheapest of all without any min or max limit. Say you want to get the limit by just typing http://www.mimovrste.com/letne-avtomobilske-pnevmatike
, then there are two tricks to achieve this.
First (Simplest)
Notice the menu on the right side which says "Cena" meaning "Price". That field get defaulted to the minimum and maximum. And this is applicable even if you use previous url. If you inspect the html it shows the value is stored in a hidden field and a text field with the name "p-min". So select an input that has a name attribute as name="p-min"
and that is your cheapest value. The advantage of this approach is it give a direct decimal value and conversiont to double is straight forward.
cheapest = doc.select("input[name=p-min]").first().attr("value");
Second
Notice the url. The sorting order is named with 'o'. So if you say o=price
in url it sorts the list in ascending order based on price and if you give it as o=_price
it give descending order of prices. So pass in a parameter "o" with value "_price" and as Pisek said select the value of first lst-product-item-price
will give you the cheapest. This will give a String value with comma and € symbol.
doc = Jsoup.connect(URL).data("0", "_price").get();
cheapest = doc.select("b.lst-product-item-price").first().text();
Put it all together
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class TyrePrice {
public static void main(String[] args) {
try {
String URL = "http://www.mimovrste.com/letne-avtomobilske-pnevmatike";
Document doc = Jsoup.connect(URL).get();
// Approach 1
String cheapest = doc.select("input[name=p-min]").first().attr("value");
System.out.println(cheapest); // Prints 31.65
// Approach 2
doc = Jsoup.connect(URL).data("0", "_price").get();
cheapest = doc.select("b.lst-product-item-price").first().text();
System.out.println(cheapest); // Prints 31,65 €
} catch (IOException e) {
e.printStackTrace();
}
}
}
Hope this helps. :)