<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-65  評論-68  文章-4  trackbacks-0

    ///////////////////////////////////////////////////
    //其實這個程序可以進一步處理進而過濾出需要的信息
    //@author Xiaoshuang
    //

    import java.sql.*;
    import java.net.*;
    import java.io.*;

    public class WeatherFilter{
     private String html;
     private String target="
    http://weather.news.sohu.com/query.php?city=北京";
     
     public WeatherFilter()throws Exception{
      this(null);
     }
     
     public WeatherFilter(String targetIn)throws Exception{
      if(targetIn!=null)
       this.target=targetIn;
      URL targetURL=new URL(target);
      HttpURLConnection conn=(HttpURLConnection)targetURL.openConnection();
      conn.connect();
      InputStream inputSteam=conn.getInputStream();
      BufferedReader bufReader=new BufferedReader(new InputStreamReader(inputSteam));
      StringBuffer buf=new StringBuffer();
      String temp;
      while((temp=bufReader.readLine())!=null){
       buf.append(temp);
      }
      html=buf.toString();
      html=html.toLowerCase();
     }
     
     public String toString(){
      return html;
     }
     
     private void disposeSpaces(){
      html=html.replaceAll(" ","");
      html=html.replaceAll("\t","");
     }
     
     private void replaceAllInTag(String tag,String replace){
      while(replaceAStyle(tag,replace));
     }
     
     private boolean replaceAStyle(String tag,String replace){
      int pageLength=html.length();
      int loc = html.indexOf("<"+tag);
      if(loc>=0){
       int loc2=html.indexOf("</"+tag+">")+8;
       StringBuffer buf=new StringBuffer();
       for(int i=0;i<loc;i++)
        buf.append(html.charAt(i));
       if(replace!=null)
        buf.append(replace);
       for(int i=loc2;i<pageLength;i++)
        buf.append(html.charAt(i));
       html=buf.toString();
       return true;
      }
      else{
       return false;
      }
     }
     
     private void markAllImages(){
      boolean dispose=false;
      do{
       StringBuffer buf=new StringBuffer();
       int pageLength=html.length();
       int end=html.indexOf("<img");
       for(int i=0;i<end;i++)
        buf.append(html.charAt(i));
       buf.append("\n");
       while(html.charAt(++end)!='>');
       for(int i=end+1;i<pageLength;i++){
        buf.append(html.charAt(i));
       }
       html=buf.toString();
       buf=null;
       System.gc();
      }while(html.indexOf("<img")>=0);
     }

     
     private void disposeAllTags(){
      int pageLength=html.length();
      StringBuffer buf=new StringBuffer();
      boolean dispose=false;
      for(int i=0;i<pageLength;i++){
       if(html.charAt(i)=='<'){
        dispose=true;
        continue;
       }
       if(html.charAt(i)=='>'){
        dispose=false;
        continue;
       }
       if(!dispose){
        buf.append(html.charAt(i));
       }
      }
      html=buf.toString();
     }
     
     private void disposeAllKeyChars(){
      int pageLength=html.length();
      StringBuffer buf=new StringBuffer();
      boolean dispose=false;
      for(int i=0;i<pageLength;i++){
       if(html.charAt(i)=='&'){
        dispose=true;
        continue;
       }
       if(html.charAt(i)==';'){
        dispose=false;
        buf.append('\n');
        continue;
       }
       if(!dispose){
        buf.append(html.charAt(i));
       }
      }
      html=buf.toString();
     }

     
     public static void main(String[] args)throws Exception{
      WeatherFilter filter;
      if(args.length==1)
       filter=new WeatherFilter(args[args.length-1]);
      else
       filter=new WeatherFilter();
      filter.replaceAllInTag("style",null);
      filter.replaceAllInTag("script",null);
      filter.markAllImages();
      filter.disposeAllTags();
      filter.disposeSpaces();
      filter.disposeAllKeyChars();
      System.err.print(filter);
     }
    }

    posted on 2005-09-15 21:18 小爽 閱讀(1212) 評論(0)  編輯  收藏 所屬分類: 我的Java
    主站蜘蛛池模板: 亚洲人成电影院在线观看| 亚洲国产香蕉碰碰人人| 亚洲欧美黑人猛交群| 日本在线高清免费爱做网站| 免费无码午夜福利片| 日韩精品免费电影| 高潮毛片无遮挡高清免费视频| 久久久久久影院久久久久免费精品国产小说 | 日本大片在线看黄a∨免费| 亚洲精品无码久久久久YW| 日韩精品免费一区二区三区| 看全免费的一级毛片| 亚洲精品人成无码中文毛片| 国产黄在线观看免费观看不卡| 成人免费视频88| 苍井空亚洲精品AA片在线播放| 亚洲?v女人的天堂在线观看| 亚洲sss综合天堂久久久| 无码国产精品一区二区免费16| 18gay台湾男同亚洲男同| 国产免费黄色无码视频| 亚洲成A人片在线观看中文| 国产免费内射又粗又爽密桃视频 | 亚洲一区精品无码| 久久久久成人精品免费播放动漫| 亚洲国产成人精品久久| 国产午夜免费福利红片| 国产在线国偷精品免费看| 亚洲精品网站在线观看不卡无广告| 国产偷伦视频免费观看| 亚洲精品国产精品乱码视色| 国产免费久久精品丫丫| 亚洲精品中文字幕无乱码| 8888四色奇米在线观看免费看| 亚洲视频在线视频| 女人18毛片水真多免费播放 | 免费毛片a在线观看67194 | 麻豆安全免费网址入口| 亚洲视频在线免费看| 国产乱弄免费视频| 免费福利在线播放|