Supposing that all your entries look like this and you want "Asia"-"Available" and so on, you can use the following regular expression (singleline):
<h3.*?>(.*?)</h3>.*?data-tooltip="(.*?)"
Parse all the results, and you will have it.
Update: the second text sample given needs a different regular expression, but either way see this complete code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace t1
{
class Program
{
public struct ServerStatus
{
public string ServerName { get; set; }
public string Status { get; set; }
}
public static IList<ServerStatus> GetStatusFromHtml(string HTMLString)
{
List<ServerStatus> result = new List<ServerStatus>();
Regex r = new Regex(@"class=""server.*?data-tooltip=""(.*?)"".*?class=""server-name"">\s*(.*?)\s*</div>", RegexOptions.Singleline);
Match m = r.Match(HTMLString);
while (m.Success)
{
result.Add(new ServerStatus() { ServerName = m.Groups[2].Value, Status = m.Groups[1].Value });
m = m.NextMatch();
}
return result;
}
static void Main(string[] args)
{
string x = @"<div class=""server alt"">
<div class=""status-icon up"" data-tooltip=""Available"">
</div>
<div class=""server-name"">
Hardcore
</div>
<span class=""clear""><!-- --></span>
</div>
<div class=""server"">
<div class=""status-icon down"" data-tooltip=""Maintenance"">
</div>
<div class=""server-name"">
USD
</div>
<span class=""clear""><!-- --></span>
</div>";
foreach (ServerStatus s in GetStatusFromHtml(x))
{
Console.WriteLine("{0}:{1}", s.ServerName, s.Status);
}
}
}
}
Update 2: using the real source.
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;
namespace t1
{
class Program
{
public struct ServerStatus
{
public string ServerName { get; set; }
public string Status { get; set; }
}
public static IList<ServerStatus> GetStatusFromHtml(string HTMLString)
{
List<ServerStatus> result = new List<ServerStatus>();
Regex r = new Regex(@"class=""server.*?data-tooltip=""(.*?)"".*?class=""server-name"">\s*(.*?)\s*</div>", RegexOptions.Singleline);
Match m = r.Match(HTMLString);
while (m.Success)
{
string ServerName = m.Groups[2].Value;
string Status = m.Groups[1].Value;
if(ServerName != string.Empty && Status != string.Empty)
{
result.Add(new ServerStatus() { ServerName = ServerName, Status = Status});
}
m = m.NextMatch();
}
return result;
}
static void Main(string[] args)
{
WebRequest request = WebRequest.Create(@"http://us.battle.net/d3/en/status");
using (WebResponse response = request.GetResponse())
{
using (StreamReader reader = new StreamReader
(response.GetResponseStream(), Encoding.UTF8))
{
string content = reader.ReadToEnd();
foreach (ServerStatus s in GetStatusFromHtml(content))
{
Console.WriteLine("{0}:{1}", s.ServerName, s.Status);
}
}
}
}
}
}