Я просмотрел документацию Обзор селектора JSoup , но у меня все еще есть проблемы.Я хочу получить информацию с веб-страницы, и эта информация хранится в таблице.Получив это, я хочу разбить его на отдельные строки, чтобы использовать его позже;но я не могу этого сделать.
У меня JSoup работает нормально, но он не работает, когда я пытаюсь сослаться на конкретную таблицу, которую я хочу, по идентификатору, например:
try
{
Document doc = Jsoup.connect( myHtml ).get();
Elements pTag = doc.select( "table#ctl00_ContentPlaceHolder1_tblPasses" );
//Elements links = doc.select( "a[href]" );
String pTagString = pTag.html();
// Set the textview to the results of the Jsoup query
setData( pTagString );
// Reset msg
msg = null;
msg = handler.obtainMessage( UPDATE_UI );
handler.sendMessage( msg );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Вот фрагмент кода HTML, который я пытаюсьчтобы добраться до:
<table id="ctl00_ContentPlaceHolder1_tblPasses" class="standardTable" cellspacing="0" cellpadding="4" rules="cols" border="2" style="background-color:White;border-color:Gray;border-width:2px;border-style:Solid;border-collapse:collapse;">
<tr class="tablehead" style="border-width:0px;border-style:None;">
<td valign="middle" rowspan="2">Date</td><td id="ctl00_ContentPlaceHolder1_MagHeader" valign="middle">Brightness</td><td align="center" colspan="3">Start</td><td align="center" colspan="3">Highest point</td><td align="center" colspan="3">End</td>
</tr><tr class="tablehead">
<td id="ctl00_ContentPlaceHolder1_MagHeader2" align="center">(<a id="ctl00_ContentPlaceHolder1_linkMagnitude" title="show definition of this term" href="glossary.aspx?term=magnitude&lat=54.5156&lng=-6.06863&loc=Unspecified&alt=0&tz=GMT">mag</a>)</td><td align="center">Time</td><td><a id="ctl00_ContentPlaceHolder1_linkAltitude" title="show definition of this term" href="glossary.aspx?term=altitude&lat=54.5156&lng=-6.06863&loc=Unspecified&alt=0&tz=GMT">Alt.</a></td><td><a id="ctl00_ContentPlaceHolder1_linkAzimuth" title="show definition of this term" href="glossary.aspx?term=azimuth&lat=54.5156&lng=-6.06863&loc=Unspecified&alt=0&tz=GMT">Az.</a></td><td align="center">Time</td><td>Alt.</td><td>Az.</td><td align="center">Time</td><td>Alt.</td><td>Az.</td>
Это только часть таблицы, есть намного больше, но сейчас я хочу добраться до этой таблицы, и это первая строка.Есть мысли?
Обновление
Я пробовал это:
Elements table = doc.select( "table#ctl00_ContentPlaceHolder1_tblPasses" );
Element first_Row = table.first();
//Elements links = doc.select( "a[href]" );
String first_Row_Strg = first_Row.html().toString();
// Set the textview to the results of the Jsoup query
setData( first_Row_Strg );
Но на самом деле возвращает всю таблицу, а непервый ряд.Должен ли я попытаться нацелиться на фактический идентификатор строки в таблице?Если да, то как ты это делаешь?