android - Jsoup parsing HTML tables (substitute plan) -
first of all, im german, don't hate me bad english ;)
im working @ moment on app school. problem is, informations need, in html file on page. there way save "td" tags in array or strings?
html code:
<!doctype html public "-//ietf//dtd html//en"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"><meta http-equiv="expires" content="0"><meta name="keywords" content="stundenplan, timetable"> <meta name="generator" content="untis 2015"> <title>untis 2015 stundenplan 2014/15 dietrich-bonhoeffer-gymnasium 1</title> <style type="text/css"> {color:#000000;} </style> <link rel="stylesheet" href="../../untisinfo.css" type="text/css"> </head> <body bgcolor="#ffffff"> <center><font size="3" face="arial" color="#000000"> <br><div id="vertretung"> <a name="1"> </a><br><b>20.4. montag</b> | <a href="#2">[ dienstag ]</a> | <a href="#3">[ mittwoch ]</a> | <a href="#4">[ donnerstag ]</a> | <a href="#5">[ freitag ]</a><p> <table class="subst" > <tr><td align="center" colspan="7" >vertretungen sind nicht freigegeben</td></tr> </table> <p> <a name="2"> </a><br><a href="#1">[ montag ]</a> | <b>21.4. dienstag</b> | <a href="#3">[ mittwoch ]</a> | <a href="#4">[ donnerstag ]</a> | <a href="#5">[ freitag ]</a><p> <table class="subst" > <tr><td align="center" colspan="7" >vertretungen sind nicht freigegeben</td></tr> </table> <p> <a name="3"> </a><br><a href="#1">[ montag ]</a> | <a href="#2">[ dienstag ]</a> | <b>22.4. mittwoch</b> | <a href="#4">[ donnerstag ]</a> | <a href="#5">[ freitag ]</a><p> <table border="3" rules="all" bgcolor="#f4f4f4" cellpadding="3" cellspacing="3"> <tr><th align="center" colspan="2">nachrichten zum tag</th></tr> <tr><td colspan="2"><b>!!! klasse 12 3.-6. std. "zeitzeugen" !!!</b> <br><b>!!! g3 (sr) 3. stunde raum o07 !!!</b> <br><b>!!! g1 (fe) und g2 (hk) 3. stunde raum u05 !!!</b></td></tr> </table> <p> <table class="subst" > <tr class='list'><th class="list" align="center">datum</th><th class="list" align="center">stunde</th><th class="list" align="center">klasse(n)</th><th class="list" align="center">(fach)</th><th class="list" align="center">fach</th><th class="list" align="center">raum</th><th class="list" align="center">vertretungs-text</th></tr> <tr class='list odd'><td class="list" align="center">22.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">06d</td><td class="list" align="center">g</td><td class="list" align="center">g</td><td class="list" align="center">o04</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">22.4.</td><td class="list" align="center">5</td><td class="list" align="center">06d</td><td class="list" align="center">d</td><td class="list" align="center"><strike>d</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">22.4.</td><td class="list" align="center">3</td><td class="list" align="center">07a</td><td class="list" align="center">g</td><td class="list" align="center">m</td><td class="list" align="center">o05</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">22.4.</td><td class="list" align="center">4</td><td class="list" align="center">07a</td><td class="list" align="center">g</td><td class="list" align="center">m</td><td class="list" align="center">o05</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">22.4.</td><td class="list" align="center">1</td><td class="list" align="center">07a</td><td class="list" align="center">m</td><td class="list" align="center"><strike>m</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">22.4.</td><td class="list" align="center">2</td><td class="list" align="center">07a</td><td class="list" align="center">m</td><td class="list" align="center"><strike>m</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">22.4.</td><td class="list" align="center">3</td><td class="list" align="center">07c</td><td class="list" align="center">g</td><td class="list" align="center">bio</td><td class="list" align="center">o08</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">22.4.</td><td class="list" align="center">4</td><td class="list" align="center">07c</td><td class="list" align="center">g</td><td class="list" align="center">bio</td><td class="list" align="center">o08</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">22.4.</td><td class="list" align="center">5</td><td class="list" align="center">07c</td><td class="list" align="center">bio</td><td class="list" align="center"><strike>bio</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">22.4.</td><td class="list" align="center">6</td><td class="list" align="center">07c</td><td class="list" align="center">bio</td><td class="list" align="center"><strike>bio</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">22.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">08a</td><td class="list" align="center">nwt</td><td class="list" align="center">nwt</td><td class="list" align="center">u03</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">22.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">08a, 08c</td><td class="list" align="center">sp</td><td class="list" align="center">sp</td><td class="list" align="center">o09</td><td class="list" align="center">aufgaben</td></tr> <tr class='list odd'><td class="list" align="center">22.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">09b</td><td class="list" align="center">m</td><td class="list" align="center">m</td><td class="list" align="center">o12</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">22.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">10b</td><td class="list" align="center">d</td><td class="list" align="center">d</td><td class="list" align="center">p201</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">22.4.</td><td class="list" align="center">5 - 6</td><td class="list" align="center">10c</td><td class="list" align="center">ek</td><td class="list" align="center">ek</td><td class="list" align="center">o06</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">22.4.</td><td class="list" align="center">5 - 6</td><td class="list" align="center">11</td><td class="list" align="center">e3</td><td class="list" align="center"><strike>e3</strike></td><td class="list" align="center">---</td><td class="list" align="center">aufgaben holen</td></tr> <tr class='list odd'><td class="list" align="center">22.4.</td><td class="list" align="center">1 - 2</td><td class="list" align="center">11</td><td class="list" align="center">as1</td><td class="list" align="center">as1</td><td class="list" align="center">p118</td><td class="list" align="center"> </td></tr> </table> <p> <a name="4"> </a><br><a href="#1">[ montag ]</a> | <a href="#2">[ dienstag ]</a> | <a href="#3">[ mittwoch ]</a> | <b>23.4. donnerstag</b> | <a href="#5">[ freitag ]</a><p> <table class="subst" > <tr class='list'><th class="list" align="center">datum</th><th class="list" align="center">stunde</th><th class="list" align="center">klasse(n)</th><th class="list" align="center">(fach)</th><th class="list" align="center">fach</th><th class="list" align="center">raum</th><th class="list" align="center">vertretungs-text</th></tr> <tr class='list odd'><td class="list" align="center">23.4.</td><td class="list" align="center">5 - 6</td><td class="list" align="center">05a</td><td class="list" align="center">bk</td><td class="list" align="center"><strike>bk</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">23.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">05a</td><td class="list" align="center">m</td><td class="list" align="center">m</td><td class="list" align="center">e24</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">23.4.</td><td class="list" align="center">5</td><td class="list" align="center">06a, 06b</td><td class="list" align="center">evr</td><td class="list" align="center">evr</td><td class="list" align="center">o01</td><td class="list" align="center">lernzirkel</td></tr> <tr class='list even'><td class="list" align="center">23.4.</td><td class="list" align="center">6</td><td class="list" align="center">06a, 06b</td><td class="list" align="center">evr</td><td class="list" align="center">evr</td><td class="list" align="center">o01</td><td class="list" align="center">lernzirkel</td></tr> <tr class='list odd'><td class="list" align="center">23.4.</td><td class="list" align="center">1 - 2</td><td class="list" align="center">06d</td><td class="list" align="center">e</td><td class="list" align="center"><strike>e</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">23.4.</td><td class="list" align="center">1 - 2</td><td class="list" align="center">07a, 07b, 07c</td><td class="list" align="center">kr</td><td class="list" align="center"><strike>kr</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">23.4.</td><td class="list" align="center">1 - 2</td><td class="list" align="center">07b, 07c</td><td class="list" align="center">evr</td><td class="list" align="center"><strike>evr</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">23.4.</td><td class="list" align="center">5</td><td class="list" align="center">08a, 08c</td><td class="list" align="center">sp</td><td class="list" align="center"><strike>sp</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">23.4.</td><td class="list" align="center">6</td><td class="list" align="center">08a</td><td class="list" align="center">sp</td><td class="list" align="center"><strike>sp</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">23.4.</td><td class="list" align="center">1 - 2</td><td class="list" align="center">09a</td><td class="list" align="center">e</td><td class="list" align="center"><strike>e</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">23.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">09a, 09b</td><td class="list" align="center">sp</td><td class="list" align="center">sp</td><td class="list" align="center">o12</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">23.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">10a, 10c, 10b</td><td class="list" align="center">kr</td><td class="list" align="center">kr</td><td class="list" align="center">o01</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">23.4.</td><td class="list" align="center">7 - 8</td><td class="list" align="center">10a</td><td class="list" align="center">m</td><td class="list" align="center"><strike>m</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">23.4.</td><td class="list" align="center">5</td><td class="list" align="center">10a</td><td class="list" align="center">e</td><td class="list" align="center">ch</td><td class="list" align="center"> </td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">23.4.</td><td class="list" align="center">6</td><td class="list" align="center">10a</td><td class="list" align="center">e</td><td class="list" align="center">ch</td><td class="list" align="center"> </td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">23.4.</td><td class="list" align="center">9</td><td class="list" align="center">10a</td><td class="list" align="center">ch</td><td class="list" align="center"><strike>ch</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">23.4.</td><td class="list" align="center">10</td><td class="list" align="center">10a</td><td class="list" align="center">ch</td><td class="list" align="center"><strike>ch</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">23.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">10c, 10b</td><td class="list" align="center">evr</td><td class="list" align="center">evr</td><td class="list" align="center">o15</td><td class="list" align="center">aufgaben</td></tr> <tr class='list odd'><td class="list" align="center">23.4.</td><td class="list" align="center">7 - 8</td><td class="list" align="center">11</td><td class="list" align="center">bk3</td><td class="list" align="center"><strike>bk3</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">23.4.</td><td class="list" align="center">1 - 2</td><td class="list" align="center">12</td><td class="list" align="center">s2</td><td class="list" align="center"><strike>s2</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">23.4.</td><td class="list" align="center">9 - 10</td><td class="list" align="center">12</td><td class="list" align="center">bk1</td><td class="list" align="center"><strike>bk1</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">23.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">12</td><td class="list" align="center">e3</td><td class="list" align="center"><strike>e3</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> </table> <p> <a name="5"> </a><br><a href="#1">[ montag ]</a> | <a href="#2">[ dienstag ]</a> | <a href="#3">[ mittwoch ]</a> | <a href="#4">[ donnerstag ]</a> | <b>24.4. freitag</b><p> <table class="subst" > <tr class='list'><th class="list" align="center">datum</th><th class="list" align="center">stunde</th><th class="list" align="center">klasse(n)</th><th class="list" align="center">(fach)</th><th class="list" align="center">fach</th><th class="list" align="center">raum</th><th class="list" align="center">vertretungs-text</th></tr> <tr class='list odd'><td class="list" align="center">24.4.</td><td class="list" align="center">1 - 2</td><td class="list" align="center">05a</td><td class="list" align="center">e</td><td class="list" align="center">e</td><td class="list" align="center">e24</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">24.4.</td><td class="list" align="center">1 - 2</td><td class="list" align="center">05b</td><td class="list" align="center">e</td><td class="list" align="center">e</td><td class="list" align="center">e23</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">24.4.</td><td class="list" align="center">1 - 2</td><td class="list" align="center">06d</td><td class="list" align="center">f pt</td><td class="list" align="center">m</td><td class="list" align="center">o04</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">24.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">07b</td><td class="list" align="center">f</td><td class="list" align="center">f</td><td class="list" align="center">o06</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">24.4.</td><td class="list" align="center">1 - 2</td><td class="list" align="center">07c</td><td class="list" align="center">m</td><td class="list" align="center"><strike>m</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">24.4.</td><td class="list" align="center">6</td><td class="list" align="center">08a</td><td class="list" align="center">e</td><td class="list" align="center"><strike>e</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">24.4.</td><td class="list" align="center">5</td><td class="list" align="center">09a</td><td class="list" align="center">e</td><td class="list" align="center">e</td><td class="list" align="center">o12</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">24.4.</td><td class="list" align="center">5</td><td class="list" align="center">10a</td><td class="list" align="center">f</td><td class="list" align="center">e</td><td class="list" align="center">o14</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">24.4.</td><td class="list" align="center">6</td><td class="list" align="center">10a</td><td class="list" align="center">e</td><td class="list" align="center"><strike>e</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">24.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">10a, 10c</td><td class="list" align="center">sw</td><td class="list" align="center">sw</td><td class="list" align="center">spo</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">24.4.</td><td class="list" align="center">1 - 2</td><td class="list" align="center">10b</td><td class="list" align="center">nwt</td><td class="list" align="center"><strike>nwt</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">24.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">11</td><td class="list" align="center">d3</td><td class="list" align="center">m3</td><td class="list" align="center">o15</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">24.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">11</td><td class="list" align="center">e3</td><td class="list" align="center"><strike>e3</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">24.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">12</td><td class="list" align="center">d3</td><td class="list" align="center"><strike>d3</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">24.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">12</td><td class="list" align="center">d2</td><td class="list" align="center"><strike>d2</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list even'><td class="list" align="center">24.4.</td><td class="list" align="center">3 - 4</td><td class="list" align="center">12</td><td class="list" align="center">d1</td><td class="list" align="center"><strike>d1</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> <tr class='list odd'><td class="list" align="center">24.4.</td><td class="list" align="center">5 - 6</td><td class="list" align="center">12</td><td class="list" align="center">ph1</td><td class="list" align="center"><strike>ph1</strike></td><td class="list" align="center">---</td><td class="list" align="center"> </td></tr> </table> <p> </div></font></center> </body> </html>
here's asynctask, executed when click on button:
private class substitute extends asynctask<void, void, void> { string monday; @override protected void doinbackground(void... voids) { document doc = null; try { doc = jsoup.connect("http://www.dbg-filderstadt.de/fileadmin/dateien/dokumente/w00000.htm").get(); } catch (ioexception e) { e.printstacktrace(); } elements myelements = doc.getelementsbyclass("subst") .first().getelementsbytag("td"); for(element element : myelements){ monday = element.owntext(); } return null; } @override protected void onpostexecute(void result) { textview tw1=(textview)findviewbyid(r.id.textview1); tw1.settext(monday); } }
the point is, code gives me text of first table "subst". how can elements other tables well?
make monday array
string[] monday
and in place of this
elements myelements = doc.getelementsbyclass("subst") .first().getelementsbytag("td");
write following
elements myelements = doc.getelementsbytag("td"); monday = new string[myelements.size()];
you td tags in html page ,
Comments
Post a Comment