WebClient.DownloadString(Uri u) : WebClient « System.Net « C# / C Sharp by API






WebClient.DownloadString(Uri u)

   

using System;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;

class MainClass
{
    private static void Main() 
    {
        string remoteUri = "http://www.java2s.com";
        
        WebClient client = new WebClient();

        Console.WriteLine("Downloading {0}", remoteUri);

        string str = client.DownloadString(remoteUri);

        MatchCollection matches = Regex.Matches(str,@"http\S+[^-,;:?]\.htm");
        
        foreach(Match match in matches) 
        {
            foreach(Group grp in match.Groups) 
            {
                string file = grp.Value.Substring(grp.Value.LastIndexOf('/')+1);
                Console.WriteLine(file);
            }
        }
    }
}

   
    
    
  








Related examples in the same category

1.WebClient.BaseAddress
2.WebClient.Credentials
3.WebClient.DownloadData
4.WebClient.DownloadFile
5.WebClient.Headers
6.WebClient.OpenRead(String url)
7.WebClient.OpenWrite
8.WebClient.ResponseHeaders
9.WebClient.UploadData
10.WebClient.UploadValues