我想在j2me中从网页中提取文本,我使用了字符串操作,但是我没有得到结果,我的代码是否正确?
网页中的字符串:
<td align="left" valign="middle" class="celebrity-details-description-txt" >
<p style="text-align: justify;">
Hero Gopichand's new movie under the direction of Chandrasekhar Yeleti is progressing at brisk pace in Ladakh. Recently, the unit has shot an extensive action scene on Gopichand, Taapsee and others under Buzkashi sport backdrop. alt="Buzkashi sport, gopichand buzkashi, gopichand new movie, buzkashi afghanisthan sport
</p>
<p style="text-align: justify;"> </p> <p style="text-align: justify;"> </p>
</td>
这是我的代码:
int tdIndex = readUrl.indexOf("<td align=\"left\" valign=\"middle\" class=\"celebrity-details-description-txt\">");
tdIndex = readUrl.indexOf(">", tdIndex);
int endtdIndex = readUrl.indexOf("</td>", tdIndex);
String content = readUrl.substring(tdIndex + 1, endtdIndex);
答案 0 :(得分:3)
在readUrl
字符串中,middle
上的class
和td
之间有一个额外的空格。我的建议是改变
int tdIndex = readUrl.indexOf("<td align=\"left\" valign=\"middle\" class=\"celebrity-details-description-txt\">");
到
int tdIndex = readUrl.indexOf("class=\"celebrity-details-description-txt\"");