问题
I want to extract text from a web page in j2me, I have used String operations,but I am not getting the result, was my code correct?
The String from a web page:
<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>
Here my CODE:
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);
回答1:
It looks like in readUrl
String there is an extra space between middle
and class
on the td
. My suggestion is to change
int tdIndex = readUrl.indexOf("<td align=\"left\" valign=\"middle\" class=\"celebrity-details-description-txt\">");
to just
int tdIndex = readUrl.indexOf("class=\"celebrity-details-description-txt\"");
来源:https://stackoverflow.com/questions/12107974/html-text-extraction-in-j2me