我用java编辑了一段在网页里面爬邮箱地址的代码!可是不知道怎么回事一运行就进入死循环,而且爬到的邮箱都是网页中页面上的第一个邮箱地址,然后一直重复的显示这个地址,这是怎么回事啊?请高手帮我看看,小弟刚学java,不懂!谢谢大家!java爬虫程序出错

解决方案 »

  1.   

    这是我的代码,刚刚搞忘写了!sorry!
    import java.io.*;
    import java.util.regex.*;
    import java.net.*;
    public class regexText2 { /**
     * @param args
     */
    public static void main(String[] args) throws Exception
    {
    // TODO Auto-generated method stub
    getMails_1(); }
    public static void getMails_1() throws Exception
    {
    URL url=new URL("http://jingyan.baidu.com/article/647f01157ea4ca7f2148a8ce.html");
    URLConnection Conn=url.openConnection();
    BufferedReader bufin=new BufferedReader(new InputStreamReader(Conn.getInputStream()));
    String line=null;
    String mailreg="\\w+@\\w+(\\.\\w+)+";
    Pattern p=Pattern.compile(mailreg);
    while((line=bufin.readLine())!=null)
    {
    Matcher m=p.matcher(line);
    while(m.find(1))
    {
    System.out.println(m.group());

    }

    }

    }}
      

  2.   

    import java.io.*;
    import java.util.regex.*;
    import java.net.*;
    public class regexText2 { /**
     * @param args
     */
    public static void main(String[] args) throws Exception
    {
    // TODO Auto-generated method stub
    getMails_1(); }
    public static void getMails_1() throws Exception
    {
    URL url=new URL("http://jingyan.baidu.com/article/647f01157ea4ca7f2148a8ce.html");
    URLConnection Conn=url.openConnection();
    BufferedReader bufin=new BufferedReader(new InputStreamReader(Conn.getInputStream()));
    String line=null;
    String mailreg="\\w+@\\w+(\\.\\w+)+";
    Pattern p=Pattern.compile(mailreg);
    while((line=bufin.readLine())!=null)
    {
    Matcher m=p.matcher(line);
    while(m.find(1))
    {
    System.out.println(m.group());

    }

    }

    }}
      

  3.   

    你好,改成这样就可以了
    while(m.find()){System.out.println(m.group);}---------- 运行java ----------
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected]输出完成 (耗时 4 秒) - 正常终止