簡易JAVA擷取網頁有效郵箱地址

來源:互聯網
上載者:User

//  簡易JAVA擷取網頁有效郵箱地址 ---by 77

 

 

 

import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class solo7 {
 public static void main(String args[]){
  new Win();
 }
}
class Win extends Frame implements ActionListener,Runnable{
 Button button;
 URL url;
 TextField text;
 TextArea area;
 byte b[]=new byte[118];
 Thread thread;
 Win(){
  text=new TextField(20);
  area=new TextArea(12,12);
  button=new Button("確定");
  button.addActionListener(this);
  thread=new Thread(this);
  Panel p=new Panel();
  p.add(new Label("輸入網址:"));
  p.add(text);
  p.add(button);
  add(area,BorderLayout.CENTER);
  add(p,BorderLayout.NORTH);
  setBounds(60,60,360,300);
  setVisible(true);
  validate();
  addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent e){
    System.exit(0);
   }
  });
 }
 public void actionPerformed(ActionEvent e){
  if(!(thread.isAlive()))
   thread=new Thread(this);
  try{
   thread.start();
  }
  catch(Exception ee){
   text.setText("正在讀取"+url);
  }
 }
 private boolean isNameAdressFormat(String email){  
   boolean isExist = false;  
   Pattern p = Pattern.compile("//w{1,}@//w{1,}

/56//w{1,}");  
   Matcher m = p.matcher(email);  
   boolean b = m.matches();  
   if(b) {   
    isExist=true;  
   } else {  
    isExist=false; 
   }  
   return isExist;  
 } 

 public void run(){
  try{
   int n=-1;
   area.setText(null);
   url=new URL(text.getText().trim());
   InputStream in=url.openStream();
   String s="";
   while((n=in.read(b))!=-1){
    s+=new String(b,0,n);
   }
   StringTokenizer fenxi=new StringTokenizer(s,"

:=,?!。 :<>&()[]{}/////"/'");
   int i=fenxi.countTokens();
   area.append("共有"+i+"個字串,有效郵箱如

下:");
   while(fenxi.hasMoreTokens()){
    String str=fenxi.nextToken();
    if(isNameAdressFormat(str))
     area.append(str+" ");
   }
  }
  catch(MalformedURLException e1){
   text.setText(""+e1);
   return;
  }
  catch(IOException e1){
   text.setText(""+e1);
   return;
  }
 }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.