Exemplo n.º 1
0
        public void LoadWords()
        {
            Console.WriteLine("И д е т   з а г р у з к а . . .");
            HttpWebRequest  WRequest         = (HttpWebRequest)WebRequest.Create("https://studyenglishwords.com/top-english-words");
            HttpWebResponse WResponse        = (HttpWebResponse)WRequest.GetResponse();
            Stream          BaseStream       = WResponse.GetResponseStream();
            StreamReader    StreamForReading = new StreamReader(BaseStream);

            bool   IsBlockOfWord = false;
            string LineForReading;
            int    Counter = 0;

            while ((LineForReading = StreamForReading.ReadLine()) != null)
            {
                string EnglishWord;

                if (LineForReading.Contains("wordBox"))
                {
                    IsBlockOfWord = true;
                    EnglishWord   = LineForReading.Replace("<td class=\"wordBox\"><a href=\"/words/", String.Empty);
                    EnglishWord   = EnglishWord.Remove(EnglishWord.IndexOf('"'));
                    EnglishWord   = EnglishWord.Replace(" ", String.Empty);
                    _wordsWithoutTranslation[Counter, 0] = EnglishWord;
                }

                if (IsBlockOfWord && LineForReading.Contains("\"percent\""))
                {
                    string LineWithPercent = LineForReading;

                    LineWithPercent = LineWithPercent.Replace("<td class=\"percent\">", String.Empty);
                    LineWithPercent = LineWithPercent.Remove(LineWithPercent.IndexOf('%'));
                    LineWithPercent = LineWithPercent.Replace(" ", String.Empty);
                    LineWithPercent = LineWithPercent.Replace(".", ",");
                    IsBlockOfWord   = false;
                    _wordsWithoutTranslation[Counter, 1] = LineWithPercent;
                    Counter++;
                }
            }

            StreamForReading.Close();
            BaseStream.Close();

            FilterDictionary();
            SortDictionary();
        }