Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Pobieranie z okien wartosc
            string url   = textBox1.Text.ToString();
            string tekst = textBox2.Text.ToString();
            string emial = textBox3.Text.ToString();

            //Sprawdzenie czy string jest pusty
            if (String.IsNullOrEmpty(url))
            {
                MessageBox.Show("Uzupelnij pole URL!");
            }
            else if (String.IsNullOrEmpty(tekst))
            {
                MessageBox.Show("Uzupelnij pole Tekst!");
            }
            else if (String.IsNullOrEmpty(emial))
            {
                MessageBox.Show("Uzupelnij pole E-mail!");
            }
            //Jezeli podano wszystkie wartosc
            else
            {
                var        doc     = new HtmlAgilityPack.HtmlDocument();
                HtmlSample docHtml = new HtmlSample(url);

                //Pobieranie zawartosci strony
                var pageHtml = docHtml.GetPageHtml();

                //Zaladowanie zawartosci strony do obiektu HtmlAgilityPack
                doc.LoadHtml(pageHtml);

                // Metoda Descendants pozwala wybrać zestaw node'ów o określonej nazwie
                var nodes = doc.DocumentNode.Descendants("img");

                //Przeszukuje wszystkie node
                foreach (var node in nodes)
                {
                    //Jeżeli znalazł obrazek z nazwą podaną w polu Tekst
                    if (node.GetAttributeValue("alt", "").Contains(tekst))
                    {
                        string scr = node.GetAttributeValue("src", "");
                        string filename;
                        New_Log(", zrodlo: " + scr + ", emial: " + emial);
                        MessageBox.Show(scr);
                        filename = docHtml.Save(scr, "hehe.jpg");
                        docHtml.CreatEmail(filename, "*****@*****.**", "dupadupa", emial);
                    }
                }
            }
        }