Reading data from a website using C#

后端 未结 4 1721
终归单人心
终归单人心 2020-12-13 05:15

I have a webpage which has nothing on it except some string(s). No images, no background color or anything, just some plain text which is not really that long in length.

4条回答
  •  天涯浪人
    2020-12-13 05:43

     WebClient client = new WebClient();
                using (Stream data = client.OpenRead(Text))
                {
                    using (StreamReader reader = new StreamReader(data))
                    {
                        string content = reader.ReadToEnd();
                        string pattern = @"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)";
                        MatchCollection matches = Regex.Matches(content,pattern);
                        List urls = new List();
                        foreach (Match match in matches)
                        {
                                urls.Add(match.Value);
                        }
    
                  }
    

提交回复
热议问题