I have searched far and wide for a number of days now trying to find the answer to the following problem. I am pretty new to Java and Android programming and have learnt mainly from copy-paste-edit scenarios, but despite there being a few tutorials around I am really struggling with this one.
I have tried htmlcleaner as my parser, and I'm sure I'm close but just cant get this right.
I am trying to parse a table of values on a website (i.e. <TR>TD,TD,TD,TD</TR>) into a standard Android SQLite database. So each row of the table would be a row in the db.
In theory this should be quite simple but I am getting snowed under with different methods and not understanding a simple clean way to do it.
Can anybody help? Please don't point me to a htmlparser or non-specific tutorial because I have worked at these for ages and can't manage a solution.
The table values I am trying to parse are here: Teams and values
EDIT:::
OK I think I'm getting close using JSoup. I can grab a value from within a [td] tag and put it to a string. However, how can I adapt the following code so that each row (i.e. within each [tr]) is iterated for each 'for', and each [td] value is put to a String array?
public class GetTable extends Activity {
static String hello;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testlayout);
try {
populateTexts();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void populateTexts() throws IOException{
String url = "http://news.bbc.co.uk/mobile/bbc_sport/rugby/competition/ru100/table/index.shtml?context=cps_ukfs";
Document doc = Jsoup.connect(url).get();
Elements links = doc.select("td");
for (Element link : links) {
hello = link.text();
TextView twittertext10 = (TextView)findViewById(R.id.testView1);
twittertext10.setText(hello);
}
}
}