java - JSoup To Get Contents of Table -
i'm trying extract temperature value (in table below 51.46) , 6.43 pressure level table below using jsoup android. please note that 51.46 , 6.43 alter new temperature , pressure level readings taken
<tr class="time"><td colspan="3">at 10-03-2014 23:15:00</td></tr> <tr><td class="param" title="temperature" rel="tooltip">temperature</td><td class="value">51.46</td><td>f</td></tr> <tr><td class="param" title="pressure" rel="tooltip">pressure</td><td class="value">6.43</td><td>psi</td></tr> <tr><td class="param" title="level" rel="tooltip">level</td><td class="value">-1.00</td><td>ft</td></tr> <tr><td class="param" title="cell end" rel="tooltip">cell end</td><td class="value">13.100</td><td>ft</td></tr>
this should work. maintain in mind need have s in between or stripped off when parsing jsoup document.
file file = new file("test2.html"); try{ document doc = jsoup.parse(file, "utf-8"); element temperaturetd = doc.select("td[title=temperature]").first(); element pressuretd = doc.select("td[title=pressure]").first(); string temperature = temperaturetd.nextelementsibling().text() + " " + temperaturetd.nextelementsibling().nextelementsibling().text(); system.out.println(string.format("temperature: %s", temperature)); string pressure level = pressuretd.nextelementsibling().text() + " " + pressuretd.nextelementsibling().nextelementsibling().text(); system.out.println(string.format("pressure: %s", pressure)); } grab (exception e){ e.printstacktrace(); }
java android android-studio jsoup
No comments:
Post a Comment