简单的网络邮箱抓取工具(附源码) (二)

2014-11-24 03:14:12 · 作者: · 浏览: 6
nel.add(b1); panel.add(b2); frame.getContentPane().add(panel, BorderLayout.NORTH); frame.getContentPane().add(jScrollPane1, BorderLayout.CENTER); frame.setSize(300, 400); frame.pack(); frame.setVisible(true); Dimension winSize = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((winSize.width - frame.getWidth()) / 2, (winSize.height - frame.getHeight()) / 2); frame.setAlwaysOnTop(true); return this; } public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException { // TODO Auto-generated method stub UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); new MainFrm().into().systemTray(); } @SuppressWarnings({ "unchecked", "deprecation", "static-access" }) @Override public void actionPerformed(ActionEvent e) { if ("提取邮箱".equals(e.getActionCommand())) { count=1; t1.setText(""); // get("http://dzh.mop.com/whbm/20060109/4/lSgg8I6063c68aS3.shtml"); String http = ""; int combo = (comb.getSelectedIndex()); switch (combo) { case 0: http = "http://www.baidu.com/s wd="; break; case 1: http = "http://www.google.com.hk/search num=50&q="; break; case 2: http = "http://www.yahoo.cn/s q="; break; case 3: http = "http://cn.bing.com/search q="; break; case 4: http = "http://www.sogou.com/web query="; break; default: http = "http://www.baidu.com/s wd="; break; } final List list = get(http + tf.getText()); m = list.size(); for (int i = 0, n = list.size(); i < n; i++) { final Map map = list.get(i); Thread tt = new Thread() { public void run() { Iterator iterator = map.values().iterator(); while (iterator.hasNext()) { String u=iterator.next(); get(u); } } }; t.add(tt); tt.start(); } } else if ("终止抓取".equals(e.getActionCommand())) { for (int i = 0; i < t.size(); i++) { t.get(i).stop(); } } else if ("1.打 开".equals(e.getActionCommand())) { frame.setVisible(true); frame.setExtendedState(frame.NORMAL); } else if ("2.退 出".equals(e.getActionCommand())) { System.exit(0); }else if ("3.关 于".equals(e.getActionCommand())) { JOptionPane.showMessageDialog(null, "本程序仅供初学参考 QQ:三二八二四七六七六"); } } @SuppressWarnings("unchecked") public List
get(String urlStr) { List list = new ArrayList(); try { URL url = new URL(urlStr); URLConnection rulConnection = url.openConnection(); HttpURLConnection httpUrlConnection = (HttpURLConnection) rulConnection; httpUrlConnection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); BufferedReader br = new BufferedReader(new InputStreamReader( httpUrlConnection.getInputStream())); String line = ""; while ((line = br.readLine()) != null) { Map map = pr(line); list.add(map); } } catch (FileNotFoundException e) { //e.printStackTrace(); } catch (IOException e) { //e.printStackTrace(); } finally { m--; if (m <= 0) { // JOptionPane.showMessageDialog(null, "提取结束"); } } return list; } @SuppressWarnings("unchecked") public Map pr(String aa) { Pattern pattern = Pattern .compile("[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+"); Pattern pattern2 = Pattern .compile("(http|ftp|https):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@ ^=%&:/~\\+#]*[\\w\\-\\@ ^=%&/~\\+#]) "); Matcher matcher = pattern.matcher(aa); Map emailMap = new HashMap(); Matcher matcher2 = pattern2.matcher(aa); Map httpMap = new HashMap(); while (matcher2.find()) { httpMap.put(matcher2.group(), matcher2.group()); } while (matcher.find()) { emailMap.put(matcher.group(), matcher.group()); } Iterator iterator = emailMap.values().iterator(); while (iterator.hasNext()) { String str = iterator.next(); t1.append("第"+(count++)+"个:"+str + "\r\n"); } return httpMap; } public void syst