首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

怎么读取html文件的内容

2011-12-19 
如何读取html文件的内容?在读取的时候,不能将htm标签读取出来。如: h1 hello,world! /h1读取出hello,wo

如何读取html文件的内容?
在读取的时候,不能将htm标签读取出来。
如: <h1> hello,world! </h1>
读取出   hello,world!

我是想先判断每行中 <和> ,然后将 <和> 中的内容跳过不读取,但是用skip好象不好怎么跳,并且这种方法也有很多其它的缺陷。


请哪位给个大概读取html文件的内容思路。

[解决办法]
孙鑫老师的,你看看有用没得?
import java.net.*;
import java.io.*;
import java.util.*;
//import java.lang.*;
public class GetGoogle{
public static void main(String[] args)throws Exception{
System.out.println( "获取日文页面 ");
getContentByLanguage( "ja ");
System.out.println( "\n ");
System.out.println( "获取中文页面 ");
getContentByLanguage( "zh-cn ");
System.out.println( "\n ");
}
public static void getContentByLanguage(String country) throws Exception{
URL urlGoogle=new URL( "http://www.google.cn ");
HttpURLConnection googleConnection=(HttpURLConnection)urlGoogle.openConnection();
googleConnection.setRequestProperty( "Accept-Language ",country);

Maprequests=googleConnection.getRequestProperties();
Set reqFields=requests.keySet();
Iterator itrReq=reqFields.iterator();
while(itrReq.hasNext()){
String Field=(String)itrReq.next();
System.out.println(Field + ": " +googleConnection.getRequestProperty(Field));

}
googleConnection.connect();
Mapresponses=googleConnection.getHeaderFields();
Set resFields=responses.keySet();
Iterator itrRes=resFields.iterator();
while(itrRes.hasNext()){
String Field=(String)itrRes.next();
System.out.println(Field + ": " +googleConnection.getHeaderField(Field));
}
InputStream iss=googleConnection.getInputStream();
BufferedReader br=new BufferedReader(new InputStreamReader(iss));
String strLine=null;
while((strLine=br.readLine())!=null){
System.out.println(strLine);
}
br.close();
googleConnection.disconnect();
}
}

热点排行