java - Separating contents while writing a file -
here brief explanation of want achieve overall:
get contents website, remove unwanted html tags, filtering it. segregating contents. if workstations put in 1 file , if servers file.
i provide brief overview of code website.
<tr class="rowlight"> <td width=0> <a href="report.asp?reportid=100&sp=service+pack+4&os=microsoft+windows+2000+server"> <img border=0 src="images/icolink3.gif" alt="open target" width=11 height=11> </a> </td> <td class=simpletextsmall> microsoft windows 2000 server </td> <td class=simpletextsmall> service pack 4 </td> <td class=simpletextsmall> 30 </td> </tr> <tr class="rowdark"> <td width=0> <a href="report.asp?reportid=100&sp=&os=microsoft+windows+7+enterprise"> <img border=0 src="images/icolink3.gif" alt="open target" width=11 height=11> </a> </td> <td class=simpletextsmall> microsoft windows 7 enterprise </td> <td class=simpletextsmall> </td> <td class=simpletextsmall> 794 </td> </tr>
till , code capable of getting above code in .csv file as
microsoft windows 2000 server service pack 4 30 microsoft windows 7 enterprise ; 794
a ";" being used in place of space.
i want servers , windows 7 separate. unable logic.
here code filtering out content (it not include opening url connection, bufferwriter, reader etc)
try { int = 0; int j = 0; while ((inputline = in.readline()) != null) { if (inputline.contains(s)) { j++; if (j >= 7) { i++; string s0 = inputline; string m = "<td class=simpletextsmall> </td>"; if (s0.contains(m)) { s0 = " "; } else { int startposition = s0.indexof(';'); int endposition = s0.indexof(';', startposition + 1); s0 = s0.substring(startposition + 1, endposition); s0 = s0.replaceall(" ", " "); s0 = s0.replaceall(",", ""); } out.write(s0); if (i != 3) { out.write(','); } if (i == 3) { = 0; out.newline(); } } } } }
here "j" , "i" mean:
since want new line created after every entry, have counter (i). helps in putting "," .csv files.
the first 7 lines of webpage contain "s" , don't need them removed them.
i hope easy understand. have been stuck on past 2 weeks.
any appreciated.
Comments
Post a Comment