<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
    主站蜘蛛池模板: 亚洲综合精品第一页| 在线观看亚洲成人| 久久久亚洲欧洲日产国码二区| 一级毛片免费在线观看网站| 国产免费AV片无码永久免费 | 亚洲va久久久噜噜噜久久狠狠| 免费一级毛片在线播放放视频| 永久在线毛片免费观看| 狠狠综合亚洲综合亚洲色| 永久免费毛片手机版在线看| 亚洲人成人网站18禁| 国产大片51精品免费观看| 最新亚洲人成无码网www电影| 日本黄页网站免费| 无码AV动漫精品一区二区免费| 亚洲视频免费在线播放| 伊人久久亚洲综合影院| 人成午夜免费大片在线观看| 伊人婷婷综合缴情亚洲五月| 国产啪精品视频网站免费尤物| 久久99久久成人免费播放| 亚洲午夜国产片在线观看| WWW免费视频在线观看播放| 久久精品国产69国产精品亚洲| 久久香蕉国产线看免费| 亚洲天堂电影在线观看| 波多野结衣久久高清免费 | 日韩成人免费视频播放| 曰批全过程免费视频免费看 | 国产l精品国产亚洲区在线观看 | 最近2019中文免费字幕| 国产精品手机在线亚洲| 国产亚洲美女精品久久久久狼| 久久这里只精品99re免费| 亚洲AV男人的天堂在线观看| 亚洲国产天堂久久综合| 91精品国产免费| 丰满亚洲大尺度无码无码专线| 亚洲欧洲日产国码无码网站| 69式国产真人免费视频| 一级A毛片免费观看久久精品|