java读取网页信息

    技术2024-10-26  23

    import java.io.BufferedReader;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;import java.util.regex.Matcher;import java.util.regex.Pattern;

    public class ReadWebPage { public static void main(String[] args) {  try {   URL url = new URL("http://www.3158.com/view/dome/lxwm.shtml");   HttpURLConnection connection = (HttpURLConnection) url.openConnection();   InputStream is = connection.getInputStream();   BufferedReader br = new BufferedReader(new InputStreamReader(is));   String line = "";   while ((line = br.readLine()) != null) {    parse(line);   }  } catch (FileNotFoundException e) {   // TODO Auto-generated catch block   e.printStackTrace();  } catch (IOException e) {   // TODO Auto-generated catch block   e.printStackTrace();  } }

     private static void parse(String line) {  // 获取邮箱  Pattern p = Pattern.compile("[//w[.-]]+@[//w[.-]]+//.[//w]+");  // 获取手机号码  // Pattern p = Pattern.compile("1[3,5]//d{9}");  Matcher m = p.matcher(line);  while (m.find()) {   System.out.println(m.group());  } }}

     

    本文来自博客,转载请标明出处:http://blog.csdn.net/wanghuailong/archive/2009/12/31/5111625.aspx

    最新回复(0)