1

I am new in Android programming. I need to get values from HTML and display it in list. Here is link http://www.hak.hr/info/cijene-goriva/

->so I need values (10,41,10.51)

<div id="div_eurosuper95">
                <table class="nowrapper fuel_segmented">
                <thead>
                    <tr>
                        <th>
                            Gorivo
                        </th>
                        <th>
                            Cijena (kn)
                        </th>
                    </tr>
                </thead>
                <tbody>

                    <tr>
                        <td class="fuel_name"><span class="vendorName">Tifon</span></br>euroSUPER 95 BS</td>
                        <td class="fuel_segmented">10,41</td>
                    </tr>

                    <tr>
                        <td class="fuel_name"><span class="vendorName">Tifon</span></br>EUROSUPER 95 
BS CLASS</td>
                        <td class="fuel_segmented">10,51</td>
                    </tr>

                    <tr>
                        <td class="fuel_name"><span class="vendorName">Crodux derivati</span></br>EUROSUPER 95 BS</td>
                        <td class="fuel_segmented">10,41</td>
                    </tr>


                    <tr>
                        <td class="fuel_name"><span class="vendorName">AdriaOil</span></br>Euro Super 95 BS TOP</td>
                        <td class="fuel_segmented">10,51</td>
                    </tr>

                </tbody>
            </table>
                </div>
2
  • are these numbers coming from a website in a XML or JSON format?? or just like these?? Commented Feb 27, 2014 at 12:52
  • there is page source, so you can see it Commented Feb 27, 2014 at 14:21

2 Answers 2

1

You can use Jsoup selector to select all the <td> tags that have are of class fuel_segmented.

Document doc = Jsoup.parse(html);
Elements fuel = doc.select("td.fuel_segmented");

This is a basic CSS selector syntax, where the td specifies the tag, and the . specifies that it is a class. If it was a specific td with an id you could've specified it as td#fuel_segmented.

This will return a collection of Element objects, represented by an Elements object.

To make it a bit more easy to see what is what, you can loop through the elements and display the corresponding fuel name.

Elements fuel = doc.select("td.fuel_segmented");
for (Element element : fuel) {
    System.out.println(element.previousElementSibling().text()
    + ": " + element.text());
}

which will output

Tifon euroSUPER 95 BS: 10,41
Tifon EUROSUPER 95 BS CLASS: 10,51
Crodux derivati EUROSUPER 95 BS: 10,41
AdriaOil Euro Super 95 BS TOP: 10,51

I suggest that you read more about how to use the selector in Jsoup to parse the data that you need. That part of the cookbook can be found here.

Sign up to request clarification or add additional context in comments.

Comments

0

To display your datas in ListView, there is a good tutorial to understand how does it work.

I really don't know where did you get these prices, on Jsoup you have all the "Cookbooks" necessary, with examples to parse html document.

Comments

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.