html - Java Pull Table Data from Site? -


new java , started learning how read html website using java i've been attempting learn how parse through , pull elements(useful data). have been searching best way , jsoup kept coming decided try out. able pull table elements there lot of useless html nice remove.. how can pull table site , have row elements there easy way jsoup?

string html = "http://beta.letsplaysoccer.com/facilities/26/teams/187822";           document doc = jsoup.connect(html).get();          elements tableelements = doc.select("table");          system.out.print(tableelements); 

thanks help!

edit: useless html in tags, class names, etc.. if wanted use table data want use game dates or not

<td> <a href="/facilities/26/games?exact_date=14-03-30">sun 03-30-14 07:25 pm</a></td> 

what pull data own gui or something

jsoup helps, you'll need navigate manually through html quite bit of pain...

here example print games played scored in first table:

import java.io.ioexception; import java.util.list;  import org.jsoup.jsoup; import org.jsoup.nodes.document; import org.jsoup.nodes.element; import org.jsoup.nodes.node; import org.jsoup.select.elements; import org.junit.test;  public class jsouptest {      @test     public void testjsoup() throws ioexception {         string html = "http://beta.letsplaysoccer.com/facilities/26/teams/187822";          document doc = jsoup.connect(html).get();         elements tableelements = doc.select("table");          element firsttable = tableelements.get(0);          list<node> firsttablerows = firsttable.childnodes().get(1).childnodes();         int numrows = firsttablerows.size();         // skip first row header         (int = 1; < numrows; i++) {             node row = firsttablerows.get(i);             if (row instanceof element) {                 node hometeam = row.childnode(5).childnode(1).childnode(0);                 node visitorteam = row.childnode(7).childnode(1).childnode(0);                 // in bold                 if(visitorteam.childnodesize() > 0 ){                     visitorteam = visitorteam.childnode(0);                 }                 node score = row.childnode(9).childnode(0);                 system.out.println(hometeam + " vs " + visitorteam + ": " + score);             }         }      } } 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -