java 过滤脚本_我写的得到天气的Java代码,其中有过滤脚本和过滤HTMLtag的函数。...
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);
}
總結(jié)
以上是生活随笔為你收集整理的java 过滤脚本_我写的得到天气的Java代码,其中有过滤脚本和过滤HTMLtag的函数。...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: radio切换控制div显示_JavaS
- 下一篇: 2017年html5行业报告,云适配发布