そのため、フォーラムからメンバープロファイルのリンクを取得して、コンソールアプリに表示しようとしています。私がやりたいのは、ウェブページからすべてのリンクを取得して印刷することです。
現在、私は次のようなページソースを取得しています:
String source = WebClient.DownloadString("URL");
私がやりたいのは、その文字列を繰り返し処理して、次のようなすべての文字列を見つけることです。
<h3 class='ipsType_subtitle'>
<strong><a href='http://www.website.org/community/user/8416-unreal/' title='View Profile'>!Unreal</a></strong>
</h3>
次に、その部分を取得したら、次のようなURLを取得します。
http://www.website.org/community/user/8416-unreal/
現在、これは私が試したコードであり、機能します。ただし、リンクの1つだけを取得します。
WebClient c = new WebClient();
String members = c.DownloadString("http://www.powerbot.org/community/members/");
int times = Regex.Matches(members, "<h3 class='ipsType_subtitle'>").Count;
Console.WriteLine(times.ToString());
for (int i = 1; i < times; i++)
{
try
{
int start = members.IndexOf("<h3 class='ipsType_subtitle'>");
members = members.Substring(start, 500);
String[] next = members.ToString().Split(new string[] { "a href='" }, StringSplitOptions.None);
String[] link = next[1].Split(' ');
Console.WriteLine(link[0].Replace("'", ""));
}
catch(Exception e) { Console.WriteLine("Failed: " + e.ToString()); }
}
Console.Read();
ありがとう。