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("
if(loc>=0){
int loc2=html.indexOf(""+tag+">")+8;
StringBuffer buf=new StringBuffer();
for(int i=0;i
buf.append(html.charAt(i));
if(replace!=null)
buf.append(replace);
for(int i=loc2;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("
for(int i=0;i
buf.append(html.charAt(i));
buf.append("\n");
while(html.charAt(++end)!='>');
for(int i=end+1;i
buf.append(html.charAt(i));
}
html=buf.toString();
buf=null;
System.gc();
}while(html.indexOf("=0);
}