0

Hey Guys I am just starting on Jsoup and have a small problem with a table. I am trying to parse car details from this website http://mywheels.ie/car-history-check/free-car-check-results/?VRN=00c31865 but don't really know how to do it. Could somebody tell me how to address the table and copy at least one element from it ? thanks in advance

Elements table = doc.select("table");
Elements row = doc.select("table[width=\"100%\"] [cellspacing=\"0px\"] [cellpadding=\"0px\"]");
Iterator<Element> iterator = row.listIterator();
while(iterator.hasNext())
{
        Element element = iterator.next();
        String id = element.attr("id");
        String classes = element.attr("class");
        String value = element.text();
        System.out.println("Id : " + id + ", classes : " + classes+ ", value : " + value);
}
2
  • What is your specific problem? Commented Oct 13, 2013 at 11:42
  • Well the code would not display any output, and i don't know what I am doing wrong Commented Oct 13, 2013 at 11:45

1 Answer 1

1

I can recommend you to create a JAVA project to test Jsoup as it is much quicker that way. I completely restructured your code. I used descriptive variable names to easier understanding. Here is the code:

    Document doc;
    try {
        doc = Jsoup.connect("http://mywheels.ie/car-history-check/free-car-check-results/?VRN=00c31865").get();

        Element containingDiv = doc.select(".free-vehicle-report-topDiv").first();
        Elements table = containingDiv.select("table");
        Elements rows = table.select("tr");

        for (Element row : rows) {
            System.out.println("label: "+row.child(0).text()+", value:"+row.child(1).text());
            // LOG.i("label: "+row.child(0).text()+", value:"+row.child(1).text());
        }


    } catch (IOException e) {
        e.printStackTrace();
    }

I tested in JAVA also, In android you may comment out the Log.i method call instead the System.out.println. It is not so difficult. Good luck.

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

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.