0

This is probably dumb question, but I can't really figure it out. I'm trying to parse html output from page: http://meteo.uwb.edu.pl/

So basically I need to extract values from table, from left side (blue text) as keys(headers) and from right side (brown text) as values. Additionaly, header labels ("Aktualna pogoda/Weather conditions: ")

My intention is to get html table from html output and then parse its row, but I can't figure it out, because html output is rather complicated. I'm starting from it:

doc = Jsoup.connect("http://meteo.uwb.edu.pl/").get();
Elements tables = doc.select("table");
for (Element row : table.select("tr"))
{
  Elements tds = row.select("td:not([rowspan])");
  System.out.println(tds.get(0).text() + "->" + tds.get(1).text());
}

But still my result is a mess. Do you have any ideas how to parse it correctly?

2 Answers 2

2

keys data from first table can be retrieved by this code:

doc.select("table").get(1).select("tbody").get(1).select("tr").get(1).select("td").get(0).select("b")

and value by this:

doc.select("table").get(1).select("tbody").get(1).select("tr").get(1).select("td").get(1).select("b")

for second table

doc.select("table").get(2).select("tbody").get(0).select("tr").get(1).select("td").get(0).select("b")

and

doc.select("table").get(2).select("tbody").get(0).select("tr").get(1).select("td").get(1).select("b")
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, your soultion looks far better than mine, I will check it
0

I managed it this way:

 doc = Jsoup.connect("http://meteo.uwb.edu.pl/").get();
 Elements tables = doc.select("td");
 Elements headers = tables.get(2).select("b");
 Elements vals = tables.get(3).select("b");
 Map all = new HashMap();

 for (int i=0;i<headers.size() ; i++) all.put(headers.get(i).text(),vals.get(i).text());

It seems to be ok.

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.