1
Answer

Email Extraction from webs

Ahsan Abbas

Ahsan Abbas

10y
812
1
I want to extract email address from html pages, here is my code which runs perfectly but the problem is it's extracts only one email id not multiple, which means it's not passing through any loop, can any tell me where can i put loop in the code.

private void btnURL_Click(object sender, EventArgs e)
        {
            string url = boxURL.Text;

            WebRequest request = WebRequest.Create(url);
            WebResponse response = request.GetResponse();
            Stream data = response.GetResponseStream();
            StreamReader sr = new StreamReader(data);

            string html = sr.ReadToEnd();

            //string regex = "\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b";
            string regex = @"[\w-]+@([\w-]+\.)+[\w-]+";
            System.Text.RegularExpressions.Regex ex = new System.Text.RegularExpressions.Regex(regex, System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            string Email = ex.Match(html).Value.Trim();
            boxEmail.Text = Email;
        }
Answers (1)