Search code examples
htmljava-melwuit

html text Extraction in j2me


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;">&nbsp;</p> <p style="text-align: justify;">&nbsp;</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);

Solution

  • 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("&lt;td align=\"left\" valign=\"middle\" class=\"celebrity-details-description-txt\">");
    

    to just

    int tdIndex = readUrl.indexOf("class=\"celebrity-details-description-txt\"");