URLをthisから検索しようとしています。これは私が取得する必要があるテーブルです:Jsoup [Android]を使用してWebページから特定のテーブルを取得する方法
<table id="h2hSum" class="competitionRanking tablesorter">
<thead>
<tr>
<th align="center">Team</th>
<th align="center">Played</th>
<th align="center">Win</th>
<th align="center">Draw</th>
<th align="center">Lose</th>
<th align="center">Score</th>
<th>Goals Scored</th>
<th>Goals Allowed</th>
</tr>
</thead>
<tbody>
<tr>
<td><a class="teamLink" href="/soccer-statistics/England/Premier-League-2016-2017/team_info_overall/676_Manchester_City_FC">Manchester City</a></td>
<td>140</td>
<td>47</td>
<td>38</td>
<td>55</td>
<td>188:205</td>
<td>1.34</td>
<td>1.46</td>
</tr>
<tr class="odd">
<td><a class="teamLink" href="/soccer-statistics/England/Premier-League-2016-2017/team_info_overall/661_Chelsea_FC">Chelsea</a></td>
<td>140</td>
<td>55</td>
<td>38</td>
<td>47</td>
<td>205:188</td>
<td>1.46</td>
<td>1.34</td>
</tr>
</tbody>
</table>
これは私が試したものです:
private class SimpleTask1 extends AsyncTask<String, String, String>
{
ProgressDialog loader;
@Override
protected void onPreExecute()
{
loader = new ProgressDialog(MainActivity.this, ProgressDialog.STYLE_SPINNER);
loader.setMessage("loading engine");
loader.show();
}
protected String doInBackground(String... urls)
{
String result1 = "";
try {
Document doc = Jsoup.connect(urls[0]).get();
Element table = doc.select("table[class=competitionRanking tablesorter]").first();
Iterator<Element> ite = table.select("td").iterator();
ite.next();
Log.w("Value 1: ",""+ ite.next().text());
Log.w("Value 2: ",""+ ite.next().text());
Log.w("Value 3: ",""+ ite.next().text());
Log.w("Value 4: ",""+ ite.next().text());
} catch (IOException e) {
}
return result1;
}
protected void onPostExecute(String sampleVal)
{
loader.dismiss();
Log.e("OUTPUT",""+sampleVal);
}
}
はしかし、これは例外をスローし、私は同様の答えをしようとしたが、テーブルが使用してアクセスされる答えは異なりますクラス名またはtdの幅。 この表のすべての値にアクセスできるようにするにはどうすればよいですか?親切に助けてください。
してください例外のスタックトレースを送信する –