1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Extracting Confirmation Code

Discussion in 'C, C++, C#' started by knockoutlocal, Apr 19, 2014.

  1. knockoutlocal

    knockoutlocal Junior Member

    Joined:
    Jun 5, 2012
    Messages:
    161
    Likes Received:
    67
    I've built a selenium bot that submits business information to different citation directories. I have captcha solving and email confirmations built in, however, I'm having trouble with some directories that send you an e-mail with a temporary then make you click a confirmation link and type the password in.

    Finding the confirmation link is not problem, but I can't figure out how to extract the confirmation code that gets sent to me.

    The e-mails will have something that says "Your temporary password is: xxxxxxxxxxxx Click on this link: http://xxxxxxxxxx and log in."

    Any suggestions on how to extract the temporary password out?
    Background:
    -Program uses:
    -seleneium framework
    -OpenPOP for e-mail
    -Written in C# Winforms

    Any help would be appreciated.
     
  2. Daagur

    Daagur Newbie

    Joined:
    Aug 22, 2012
    Messages:
    33
    Likes Received:
    60
    Home Page:
    If the emails are in html format you can use HTMLAgilityPack to get the password.
    Otherwise I would use regular expressions to find the password
     
    • Thanks Thanks x 1
  3. Gogol

    Gogol Elite Member

    Joined:
    Sep 10, 2010
    Messages:
    3,066
    Likes Received:
    2,872
    Gender:
    Male
    Although it is not my language, but I will surely use regex for doing this if I was you. try searching at regexlib.com
     
    • Thanks Thanks x 1
  4. knockoutlocal

    knockoutlocal Junior Member

    Joined:
    Jun 5, 2012
    Messages:
    161
    Likes Received:
    67
    I've been trying to find a solution that doesn't involve reading hieroglyphics(Regex) but I guess I better man up and start learning it.

    Thanks for the suggestions.
     
  5. Macthetrix

    Macthetrix Regular Member

    Joined:
    Feb 21, 2013
    Messages:
    379
    Likes Received:
    390
    Occupation:
    The Boss
    Location:
    Silicon Valley
    Code:
    public string GetConfirmationCode(string input)
    {
           Match match1 = Regex.Match(input, "is: (.*?) Click");
           return match1.Value.Replace("is: ","").Replace(" Click","");
    }
    
    use Regex to extract it. Find the pattern and (.*?) will extract everything between those two patterns. Then replace the junk with "" or string.Empty

    make sure to refrence: using System.Text.RegularExpressions
    Hope this helps.
     
    • Thanks Thanks x 1
    Last edited: Apr 20, 2014
  6. Macthetrix

    Macthetrix Regular Member

    Joined:
    Feb 21, 2013
    Messages:
    379
    Likes Received:
    390
    Occupation:
    The Boss
    Location:
    Silicon Valley
    here you can see it in action:
    Code:
    using System;
    using System.Text.RegularExpressions;
    
    
    namespace test
    {
        class Program
        {
            static void Main(string[] args)
            {
                string input = "The e-mails will have something that says Your temporary password is: xxxxxxxxxxxx Click on this link: http://google.com and log in.";
                Console.WriteLine(GetConfirmationCode(input));
                Console.ReadLine();
            }
    
    
            private static string GetConfirmationCode(string input)
            {
                Match match1 = Regex.Match(input, "is: (.*?) Click");
                return match1.Value.Replace("is: ", "").Replace(" Click", "");
            }
        }
    }
    
    // prints xxxxxxxxxxxx
    
    
    
    View attachment 48852
     
    • Thanks Thanks x 1
  7. squark

    squark Junior Member

    Joined:
    May 22, 2008
    Messages:
    156
    Likes Received:
    1,207
    A little cleaner would be to skip the string replacing and just return the captured text. So all your code, but with this for the return statement...

    Code:
    return match1.Groups[1].Value;
    That will give more power when you get into increasingly complex regular expressions, too.
     
    • Thanks Thanks x 1
  8. knockoutlocal

    knockoutlocal Junior Member

    Joined:
    Jun 5, 2012
    Messages:
    161
    Likes Received:
    67
    I ended up using html agility pack (I solved it before I saw the responses above). Thank you all for your help