Do you mean something like this:
string numberOfFriends;
HtmlElementCollection elems = webBrowser1.Document.GetElementsByTagName( "div" );
foreach( HtmlElement elem in elems )
{
string className = elem.GetAttribute( "className" );
if( !string.IsNullOrEmpty( className ) && "alertText".Equals( className ) )
{
string content = elem.InnerText;
if( Regex.IsMatch( content, "\\d+ friends joined" ) )
{
numberOfFriends = Regex.Match( content, "(\\d+) friends joined" ).Groups[ 1 ].Value;
}
}
}
I am not entirely sure if Regex are totally correct, but the rest should work.
Edit: Changed Groups[ 0 ]
to Groups[ 1 ]
- IIRC first group is entire match.
Edit 2: Changed elem.GetAttribute( "class" )
to elem.GetAttribute( "className" )
- fixed name of attribute and fixed variable name (class
to className
).