Hi everyone,
I wrote this code and it seems it's work
First split the html using the html code <TD class="regular" height="18" width="81">
then loop in other method (getStockItem(ary[i])) to get the pricesCode:String myContent = new String (Content); String[] ary = myContent.split("<(?i)td class=\"regular\" height=\"18\" width=\"81\">"); System.out.println("# of Stocks: " + (ary.length-1));
Code:for(int i=1;i<ary.length;i++){ List_Of_Stocks.add(getStockItem(ary[i]));}
Code:private static Collection<String> getStockItem(String Item){ Pattern pattern = null; Matcher matcher = null; //String[] ItemInfo = new String[4]; Collection<String> ItemInfo = new ArrayList<String>(); Item = Item.replaceAll("[\n\t\r]",""); pattern = Pattern.compile( "<A href=[^>]*+>([^><]*)</a>", Pattern.CASE_INSENSITIVE ); matcher = pattern.matcher( Item ); if(matcher.find()){ ItemInfo.add(matcher.group().replaceAll("<.*?>","").trim()) ; }else{ ItemInfo.add("N/A"); System.err.println("no name!!"); } pattern = Pattern.compile( "<(?i)td (?i)class=[^>]*+>([^><]*)</(?i)td>", Pattern.CASE_INSENSITIVE ) ; matcher = pattern.matcher( Item ) ; while(matcher.find()){ ItemInfo.add(matcher.group().replaceAll("<.*?>","").trim()); } return ItemInfo; }
What do you think about the code ?




Reply With Quote