私は、リストからチェックされたURLチェッカープログラムを作成し、有効なサブリンクを再帰的に返します。すべてのサブリンクをチェックします。私はこのような100以上のメインページを持っており、私はすべてのサブとこれらのサイトをチェックします。 1つのサイトに対して平均3分かかる特に最初のHtmlコード(サンプル文字列 "HtmlCode = client.DownloadString(Link);")では時間がかかり、他のものは最初のものより速くなります。私はプログラムを繰り返し実行し、リンクを制御し、リンクが壊れていると警告します。どうすれば私のプログラムはより速くなりますか?私のURLチェッカープログラムをもっと速くするには?
public Form1()
{
InitializeComponent();
List<KeyValuePair<string, bool>> UrlS = Link_Bul_v2("http://www.asdfhg.com", new List<string>(), new List<KeyValuePair<string, bool>>());
List<KeyValuePair<string, bool>> UrlS2 = Link_Bul_v2("http://www.huuene.com", new List<string>(), new List<KeyValuePair<string, bool>>());
}
string UrlSadelesti(string Link)
{
return Link.Replace("https://", "").Replace("http://", "").Replace("www.", "");
}
WebClient client = new WebClient();
private List<KeyValuePair<string, bool>> Link_Bul_v2(string Link, List<string> HList, List<KeyValuePair<string, bool>> CList)
{
try
{
string HtmlCode = client.DownloadString(Link);
//if(HtmlCode.
CList.Add(new KeyValuePair<string, bool>(Link, true));
var Link_Short = UrlSadelesti(Link).Split('/')[0];
//HList.Add(Link_Short);
string DLink;
int IndexH = 0;
while (true)
{
IndexH = HtmlCode.IndexOf("href", IndexH);
if (IndexH == -1) { break; }
if (HtmlCode[IndexH - 1] == '.')
{
IndexH = IndexH + 1;
}
else
{
var IndexD1 = HtmlCode.IndexOf('"', IndexH);
var IndexD2 = HtmlCode.IndexOf('"', IndexD1 + 1);
var length = IndexD2 - (IndexD1 + 1);
DLink = HtmlCode.Substring(IndexD1 + 1, length);
IndexH = IndexD2;
if ((DLink.Contains(".css") == false))
{
if (DLink.Contains("http://") || DLink.Contains("https://"))
{
if (DLink.Contains(Link_Short) == false)
continue;
}
if (DLink.Contains("#"))
{
continue;
}
DLink = UrlSadelesti(DLink).Replace(Link_Short, "");
if (DLink.Length == 1)
continue;
if (HList.Count(p => p.Contains(DLink)) == 0)
{
if (DLink.Contains("http://") || DLink.Contains("https://"))
{
HList.Add(Link_Short + "/" + DLink);
}
else
{
HList.Add("http://" + Link_Short + "/" + DLink);
}
}
}
}
}
}
catch
{
CList.Add(new KeyValuePair<string, bool>(Link, false));
if (!HList.Contains(Link))
HList.Add(Link);
if (UrlSadelesti(Link).Split('/').Count() > 1)
{
Link_Bul_v2("http://" + UrlSadelesti(Link).Split('/')[0], HList, CList);
}
}
foreach (string s in HList)
{
if (CList.Count(p => p.Key.Contains(s)) == 0)
{
Link_Bul_v2(s, HList, CList);
}
}
return CList;
}
ない答えが、ジヌー(http://xenus-link-sleuth.en.softonic.com/) –
ありがとう、私はこれを行うプログラムがあることを知っているが、私は私のC#を開発しようとしている。 – witchqueen