Пример #1
0
        private void BtnCheck_Click(object sender, RoutedEventArgs e)
        {
            if (TextBoxFind.Text != "")
            {
                try
                {
                    MyData.MyCollection.Clear();
                    SetSymbolCount = 0;
                    ContentResult  = pars.ParseByAngle(int.Parse(TextBoxFind.Text), TextBoxSection.Text);

                    for (int i = 0; i < ContentResult.TitleResult.Count; i++)
                    {
                        SetSymbolCount++;
                        MyData.MyCollection.Add(new DataModel()
                        {
                            Id      = SetSymbolCount,
                            Url     = ContentResult.UrlResult[i],
                            Image   = new Uri(ContentResult.TitleResult[i]),
                            Checked = false
                        });
                    }
                    listView.ItemsSource = MyData.MyCollection;
                    CountValue.Text      = Convert.ToString(SetSymbolCount);
                }
                catch (Exception ex)
                {
                    message.ShowError(ex.Message);
                }
            }
            else
            {
                message.ShowExclamation("Не корректный ввод данных. Проверьте правильность заполнения.");
            }
        }
Пример #2
0
        public ParsResult ParseByAngle(int number, string section)
        {
            string    firstSymb = "https://2ch.hk/";
            string    url       = firstSymb + section + "/res/" + number + ".html";
            WebClient wc        = new WebClient();

            wc.Encoding = Encoding.UTF8;
            string Response = wc.DownloadString(url);
            var    parser   = new HtmlParser();
            var    search   = parser.ParseDocument(Response);
            var    result   = search.GetElementsByClassName("post__file-attr").ToArray();

            ParsResult FinalResult = new ParsResult();

            foreach (var b in result)
            {
                string   patternUrl   = "href='".Replace("'", "\"") + "/" + section;
                string   patternTitle = "href='".Replace("'", "\"") + "http://www.google.com/searchbyimage?image_url=https://2ch.hk/";
                string[] splitted     = b.InnerHtml.Split();
                string   tempUrl      = "";
                string   tempTitle    = "";
                for (int i = 0; i < splitted.Length; i++)
                {
                    if (splitted[i].StartsWith(patternUrl))
                    {
                        tempUrl += splitted[i];
                    }
                    else if (splitted[i].StartsWith(patternTitle))
                    {
                        tempTitle += splitted[i];
                    }
                }
                if (tempUrl != "")
                {
                    string subStringUrl     = @"href=""";
                    string finalUrl         = tempUrl.Remove(0, subStringUrl.Length);
                    string finalUrlResult   = firstSymb + finalUrl.Remove(finalUrl.Length - 1, 1);
                    string finalTitle       = tempTitle.Remove(0, 52);
                    string finalTitleResult = finalTitle.Remove(finalTitle.Length - 1, 1);
                    FinalResult.TitleResult.Add(finalTitleResult);
                    FinalResult.UrlResult.Add(finalUrlResult);
                }
            }

            return(FinalResult);
        }