Esempio n. 1
0
        public static void UpdateMetadataAttributesOnImage(GeckoElement img, PalasoImage imageInfo)
        {
            //see also Book.UpdateMetadataAttributesOnImage(), which does the same thing but on the document itself, not the browser dom
            img.SetAttribute("data-copyright",
                             String.IsNullOrEmpty(imageInfo.Metadata.CopyrightNotice) ? "" : imageInfo.Metadata.CopyrightNotice);

            img.SetAttribute("data-creator", String.IsNullOrEmpty(imageInfo.Metadata.Creator) ? "" : imageInfo.Metadata.Creator);


            img.SetAttribute("data-license", imageInfo.Metadata.License == null ? "" : imageInfo.Metadata.License.ToString());
        }
Esempio n. 2
0
        private void ChangeDisplayGecko(ListPagePattern currentPattern)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(lastTitleXPath))
                {
                    Gecko.DOM.XPathResult oldTemp  = geckoWebBrowser.Document.EvaluateXPath(lastTitleXPath);
                    GeckoNode[]           oldNodes = oldTemp.GetNodes().ToArray();
                    for (int i = 0; i < oldNodes.Length; i++)
                    {
                        GeckoElement toNoGreen = oldNodes[i] as GeckoElement;
                        toNoGreen.SetAttribute("style", ""); //将大框标为无色
                    }
                }

                Gecko.DOM.XPathResult temp  = geckoWebBrowser.Document.EvaluateXPath(currentPattern.Path.ItemRootXPath);
                GeckoNode[]           nodes = temp.GetNodes().ToArray();
                for (int i = 0; i < nodes.Length; i++)
                {
                    GeckoElement toGreen = nodes[i] as GeckoElement;
                    toGreen.SetAttribute("style", "border:1px solid #F00;background-color:#87CEEB;"); //将大框标为红框蓝底
                }
                lastTitleXPath = currentPattern.Path.ItemRootXPath;
            }
            catch { }
        }
Esempio n. 3
0
        public void ChangePicture(string bookFolderPath, GeckoElement img, PalasoImage imageInfo, IProgress progress)
        {
            var imageFileName = ProcessAndCopyImage(imageInfo, bookFolderPath);

            img.SetAttribute("src", imageFileName);
            UpdateMetdataAttributesOnImgElement(img, imageInfo);
        }
Esempio n. 4
0
        private void Procedure(Uri uri, GeckoWindow window, String file)
        {
            try
            {
                Action <FlowModelData> action;
                String next;
                Action <FlowModelData> callback;
                flow.Procedure(uri, out action, out next, out callback);
                if (window != null)
                {
                    GeckoElement script = this.Document.CreateElement("script");
                    script.SetAttribute("type", "text/javascript");
                    script.TextContent = "window.alert = function(){};";
                    window.Document.OwnerDocument.Head.AppendChild(script);
                    using (AutoJSContext context = new AutoJSContext(this.Window))
                    {
                        string result;
                        context.EvaluateScript("window.alert = function(){};", (nsISupports)window.DomWindow, out result);
                    }
                    flowModelData.Document = window.Document.OwnerDocument;
                }
                flowModelData.Uri          = uri;
                flowModelData.NextUrl      = next;
                flowModelData.CallBack     = callback;
                flowModelData.IsNextScrap  = true;
                flowModelData.IsSkipAction = false;
                if (file != null)
                {
                    flowModelData.File = new FileInfo(file);
                }
                action(flowModelData);
                if (flowModelData.IsSkipAction)
                {
                    return;
                }
                if (flowModelData.CallBack != null)
                {
                    flowModelData.CallBack(flowModelData);
                }
                if (!String.IsNullOrEmpty(flowModelData.NextUrl))
                {
                    this.Navigate(flowModelData.NextUrl);
                }
                if (!flowModelData.IsNextScrap)
                {
                    //resultParameter.Endtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    flow.End(flowModelData);
                    Scraper.Exit();
                }
            }
            catch (Exception ex)
            {
                //resultParameter.ResultCD = "9999";
                //resultParameter.ResultMSG = ex.ToString();

                flow.Error(ex);
                logger.Error(ex.ToString());
                Scraper.Exit();
            }
        }
Esempio n. 5
0
        protected void ExcuteJavascript(GeckoDocument document, String script)
        {
            GeckoElement scriptelement = document.CreateElement("script");

            scriptelement.SetAttribute("type", "text/javascript");
            scriptelement.TextContent = script;
            document.Head.AppendChild(scriptelement);
        }
        void browser_DocumentCompleted(object sender, System.EventArgs e)
        {
            //unsubscribe
            _browser.DocumentCompleted -= browser_DocumentCompleted;
            GeckoElement rt = _browser.Document.CreateElement("div");

            rt.SetAttribute("id", "blocker");
            rt.SetAttribute
            (
                "style",
                "position: fixed;"
                + "top: 0px;"
                + "left: 0px;"
                + "width: 100%;"
                + "height: 100%;"
                + "opacity: 0.0;"
                + "background-color: #111;"
                + "z-index: 9000;"
                + "overflow: auto;"
            );
            _browser.Document.Body.AppendChild(rt);
        }
Esempio n. 7
0
        public bool setFieldValue(String cField, String cKeyValue)
        {
            GeckoElement voGecko = getGeckoElement(cField);

            if (voGecko != null)
            {
                voGecko.SetAttribute("value", cKeyValue);
                return(true);
            }

            HtmlElement voHtml = getHtmlElement(cField);

            if (voHtml != null)
            {
                voHtml.SetAttribute("value", cKeyValue);
                return(true);
            }

            return(false);
        }
Esempio n. 8
0
        public static void TranslateDocument(GeckoWebBrowser wb, string language)
        {
            try
            {
                string jso = "function googleTranslateElementInit()" + " { new google.translate.TranslateElement({  " + "pageLanguage: '" + language + "'" + "  }, 'google_translate_element');" + "}";

                GeckoElement el = wb.Document.CreateElement("DIV");
                el.SetAttribute("id", "google_translate_element");
                wb.Document.Body.AppendChild(el);
                GeckoElement sco = wb.Document.CreateElement("SCRIPT");
                sco.TextContent = jso;
                wb.Document.Body.AppendChild(sco);

                GeckoElement sct = wb.Document.CreateElement("SCRIPT");
                sct.SetAttribute("src", "http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit");
                wb.Document.Body.AppendChild(sct);
            }
            catch
            {
            }
        }
Esempio n. 9
0
        public void SignIn(string userId, string passId, string buttonId)
        {
            GeckoElement elementById = this.geckoWeb.Document.GetElementById("Userid");

            if (elementById != null)
            {
                elementById.SetAttribute("value", "AVTORITET");
            }
            GeckoElement element2 = this.geckoWeb.Document.GetElementById("Passwd");

            if (element2 != null)
            {
                element2.SetAttribute("value", "Hugoboss2030");
            }
            GeckoElement element3 = this.geckoWeb.Document.GetElementById("LoginButton");

            if (element3 != null)
            {
                new GeckoInputElement(element3.DomObject).Click();
            }
        }
Esempio n. 10
0
        protected override void OnDocumentCompleted(Gecko.Events.GeckoDocumentCompletedEventArgs e)
        {
            base.OnDocumentCompleted(e);
            try
            {
                Func <GeckoDocument, Uri, Boolean> action = flow.Procedure(e.Uri);
                GeckoElement script = this.Document.CreateElement("script");
                script.SetAttribute("type", "text/javascript");
                script.TextContent = "window.alert = function(){};";
                this.Document.Head.AppendChild(script);

                if (!action(this.Document, e.Uri))
                {
                    flow.End();
                    Scraper.Exit();
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                Scraper.Exit();
            }
        }
Esempio n. 11
0
        private void gecko_Navigated(object sender, GeckoNavigatedEventArgs e)
        {
            GeckoElement gaia_loginbox = gecko.Document.GetElementById("gaia_loginbox");

            if (gaia_loginbox == null)
            {
                GeckoElement header = gecko.Document.GetElementById("header");
                if (header != null)
                {
                    header.SetAttribute("style", "display:none;");
                }

                GeckoElement oneGoogleWrapper = gecko.Document.GetElementById("oneGoogleWrapper");
                if (oneGoogleWrapper != null)
                {
                    oneGoogleWrapper.SetAttribute("style", "display:none;");
                }

                GeckoElement coloredBar = gecko.Document.GetElementById("coloredBar");
                if (coloredBar != null)
                {
                    coloredBar.SetAttribute("style", "display:none;");
                }

                GeckoElement headerBar = gecko.Document.GetElementById("headerBar");
                if (headerBar != null)
                {
                    headerBar.SetAttribute("style", "padding-top:0px;");
                    GeckoElement gUser = gecko.Document.GetElementById("guser");

                    GeckoElement username = (GeckoElement)gUser.FirstChild.ChildNodes[2];
                    username.SetAttribute("style", "display:none;");

                    foreach (GeckoNode el in gUser.FirstChild.ChildNodes)
                    {
                        if ((el.HasAttributes) && (el.Attributes["id"] != null))
                        {
                            {
                                GeckoElement element = (GeckoElement)el;
                                if (element.Id != "gb_71")
                                {
                                    element.SetAttribute("style", "display:none;");
                                }
                            }
                        }
                        if (el.TextContent.Contains("|"))
                        {
                            el.TextContent = "";
                        }
                    }

                    GeckoElement breadcrumbs = gecko.Document.GetElementById("breadcrumbs");
                    breadcrumbs.SetAttribute("style", "margin-left:176px;");

                    GeckoElement parentEl = breadcrumbs.Parent;
                    parentEl.InsertBefore((GeckoNode)gUser, (GeckoNode)breadcrumbs);

                    GeckoNode navtab = (GeckoNode)headerBar.LastChild.FirstChild;
                    if (navtab != null)
                    {
                        GeckoElement navtabEl = (GeckoElement)navtab;
                        navtabEl.SetAttribute("style", "width:171px;margin-top:25px;");
                    }
                }

                GeckoElement nav = gecko.Document.GetElementById("nav");
                if (nav != null)
                {
                    nav.SetAttribute("style", "width:151px;");
                }
            }
        }
Esempio n. 12
0
        private void LoadSearchParameters(Point point)
        {
            GeckoElement element = wbElementRecorder.DomDocument.ElementFromPoint(point.X, point.Y);

            string savedId  = element.GetAttribute("id");
            string uniqueId = Guid.NewGuid().ToString();

            element.SetAttribute("id", uniqueId);

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(element.OwnerDocument.GetElementsByTagName("html")[0].OuterHtml);
            element.SetAttribute("id", savedId);
            HtmlNode node = doc.GetElementbyId(uniqueId);

            _xPath        = node.XPath.Replace("[1]", "");
            _name         = element.GetAttribute("name") == null ? "" : element.GetAttribute("name");
            _id           = element.GetAttribute("id") == null ? "" : element.GetAttribute("id");;
            _tagName      = element.TagName;
            _className    = element.GetAttribute("class") == null ? "" : element.GetAttribute("class");
            _linkText     = element.TagName.ToLower() != "a" ? "" : element.TextContent;
            _cssSelectors = GetCSSSelectors(element);

            string cssSelectorString = string.Join(", ", GetCSSSelectors(element));

            LastItemClicked   = $"[XPath:{_xPath}].[ID:{_id}].[Name:{_name}].[Tag Name:{_tagName}].[Class:{_className}].[Link Text:{_linkText}].[CSS Selector:{cssSelectorString}]";
            lblSubHeader.Text = LastItemClicked;

            SearchParameters = NewSearchParameterDataTable();
            if (IsRecordingSequence)
            {
                foreach (DataRow row in _parameterSettings.Rows)
                {
                    switch (row[1].ToString())
                    {
                    case "XPath":
                        SearchParameters.Rows.Add(row[0], "\"XPath\"", $"\"{_xPath}\"");
                        break;

                    case "ID":
                        SearchParameters.Rows.Add(row[0], "\"ID\"", $"\"{_id}\"");
                        break;

                    case "Name":
                        SearchParameters.Rows.Add(row[0], "\"Name\"", $"\"{_name}\"");
                        break;

                    case "Tag Name":
                        SearchParameters.Rows.Add(row[0], "\"Tag Name\"", $"\"{_tagName}\"");
                        break;

                    case "Class Name":
                        SearchParameters.Rows.Add(row[0], "\"Class Name\"", $"\"{_className}\"");
                        break;

                    case "Link Text":
                        SearchParameters.Rows.Add(row[0], "\"Link Text\"", $"\"{_linkText}\"");
                        break;

                    case "CSS Selector":
                        for (int i = 0; i < _cssSelectors.Count; i++)
                        {
                            SearchParameters.Rows.Add(row[0], $"\"CSS Selector {i + 1}\"", $"\"{_cssSelectors[i]}\"");
                        }
                        break;
                    }
                }
            }
            else
            {
                SearchParameters.Rows.Add(true, "\"XPath\"", $"\"{_xPath}\"");
                SearchParameters.Rows.Add(false, "\"ID\"", $"\"{_id}\"");
                SearchParameters.Rows.Add(false, "\"Name\"", $"\"{_name}\"");
                SearchParameters.Rows.Add(false, "\"Tag Name\"", $"\"{_tagName}\"");
                SearchParameters.Rows.Add(false, "\"Class Name\"", $"\"{_className}\"");
                SearchParameters.Rows.Add(false, "\"Link Text\"", $"\"{_linkText}\"");
                for (int i = 0; i < _cssSelectors.Count; i++)
                {
                    SearchParameters.Rows.Add(false, $"\"CSS Selector {i + 1}\"", $"\"{_cssSelectors[i]}\"");
                }
            }
        }
Esempio n. 13
0
        private void geckoWebBrowser1_DocumentCompleted(object sender, Gecko.Events.GeckoDocumentCompletedEventArgs e)
        {
            if (e.Uri.ToString().Contains("https://www.turkhackteam.org/private.php"))
            {
                mesajsayisi = 0;
                tempo.Clear();
                listView1.Items.Clear();
                //listBox1.Items.Add("Sayfa doldu: " + e.Uri.ToString());
                foreach (GeckoHtmlElement bugun in geckoWebBrowser1.Document.GetElementsByTagName("tbody"))
                {
                    if (bugun.GetAttribute("id") == "collapseobj_pmf0_today")
                    {
                        var icerik = bugun.GetElementsByTagName("tr");
                        foreach (var childnode in icerik)
                        {
                            var icerik2 = childnode.GetElementsByTagName("td");

                            foreach (var child2 in icerik2)
                            {
                                if (child2.GetAttribute("class") == "alt1 alt1Active")
                                {
                                    tempo.Add(child2);

                                    mesajsayisi += 1;
                                    ListViewItem lvi = new ListViewItem(child2.TextContent);
                                    lvi.SubItems.Add(child2.GetAttribute("id"));
                                    listView1.Items.Add(lvi);
                                }
                            }
                        }
                    }
                }
                label4.Text = mesajsayisi.ToString();
                if (timer1.Enabled == false)
                {
                    timer1.Interval = (int)numericUpDown1.Value * 1000;
                    timer1.Enabled  = true; timer1.Start();
                }
                acildi = true;
            }
            else if (e.Uri.ToString().Contains("#login"))
            {
                listBox1.Items.Add("Sayfa doldu: " + e.Uri.ToString());
                GeckoElement username = geckoWebBrowser1.Document.GetElementById("navbar_username");
                username.SetAttribute("value", textBox1.Text);

                GeckoElement password = geckoWebBrowser1.Document.GetElementById("navbar_password");
                password.SetAttribute("value", textBox2.Text);
                listBox1.Items.Add("Üyelik bilgileri aktarıldı: " + textBox1.Text + "  " + Convert.ToBase64String(Encoding.UTF8.GetBytes(textBox2.Text)));

                foreach (GeckoHtmlElement girisButonu in geckoWebBrowser1.Document.GetElementsByTagName("input"))
                {
                    if (girisButonu.GetAttribute("class") == "spe-button4")
                    {
                        girisButonu.Click();
                        listBox1.Items.Add("Giriş Yap butonuna tıklandı.");
                        break;
                    }
                }
            }
            else if (e.Uri.ToString().Contains("https://www.turkhackteam.org/login.php?do=login"))
            {
                listBox1.Items.Add("Sayfa doldu: " + e.Uri.ToString());
                GeckoHtmlElement element         = null;
                GeckoElement     geckoDomElement = geckoWebBrowser1.Document.DocumentElement;
                if (geckoDomElement is GeckoHtmlElement)
                {
                    element = (GeckoHtmlElement)geckoDomElement;
                    string icerik = element.InnerHtml;
                    if (icerik.Contains("Yanlış kullanıcı adı veya şifre girildi."))
                    {
                        listBox1.Items.Add("Yanlış kullanıcı adı veya şifre girildi.");
                        MessageBox.Show("Yanlış kullanıcı adı veya şifre", "Giriş", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
            }
            else if (e.Uri.ToString() == "https://www.turkhackteam.org/")
            {
                try
                {
                    foreach (GeckoHtmlElement pp in geckoWebBrowser1.Document.GetElementsByTagName("img"))
                    {
                        if (pp.GetAttribute("title") == "Avatar")
                        {
                            using (WebClient baytar = new WebClient())
                            {
                                baytar.Headers.Add("User-Agent: Other");
                                using (Stream sago_go_go = baytar.OpenRead("https://www.turkhackteam.org/" + pp.GetAttribute("src")))
                                {
                                    pictureBox1.Image = Image.FromStream(sago_go_go);
                                }
                            }
                            break;
                        }
                    }
                }catch (Exception ex) { listBox1.Items.Add("Profil fotosu hatası: " + ex.Message); }
                listBox1.Items.Add("Sayfa doldu: " + e.Uri.ToString());
                geckoWebBrowser1.Navigate("https://www.turkhackteam.org/private.php");
            }
        }