Web サイトからすべての http リンクを検索するプログラムを C# で作成するタスクがあります。今、私はそのような関数を書きました:
async static void DownloadWebPage(string url)
{
using (HttpClient client = new HttpClient())
using (HttpResponseMessage response = await client.GetAsync(url))
using (HttpContent content = response.Content)
{
string[] resArr;
string result = await content.ReadAsStringAsync();
resArr = result.Split(new string[] {"href"}, StringSplitOptions.RemoveEmptyEntries);//splitting
//here must be some code-string which finds all neccessary http-links from resArr
Console.WriteLine("Main page of " + url + " size = " + result.Length.ToString());
}
}
この関数を使用して Web ページのコンテンツを文字列にロードし、この文字列を解析して結果を配列に書き込み、"href"-splitter を使用してから、"href" サブストリングを含む文字列のすべての配列ユニットをチェックします。 http リンクを含む文字列を取得できます。文字列が分割されているときに問題が発生します.httpリンクを見つけることができないため、これはこの文字列のコンテンツ形式が原因であると考えています.どのように修正しますか?