Example #1
0
 private void SetValue(HtmlElementCollection elementCollection, string attr, string attrValue)
 {
     foreach (HtmlElement element in elementCollection)
     {
         SetValue(element, attr, attrValue);
     }
 }
Example #2
0
        private string PrintDom(HtmlElementCollection elemColl, System.Text.StringBuilder returnStr, Int32 depth)
        {
            System.Text.StringBuilder str = new System.Text.StringBuilder();

            foreach (HtmlElement elem in elemColl)
            {
                string elemName;

                elemName = elem.GetAttribute("ID");
                if (elemName == null || elemName.Length == 0)
                {
                    elemName = elem.GetAttribute("name");
                    if (elemName == null || elemName.Length == 0)
                    {
                        elemName = "<no name>";
                    }
                }

                str.Append(' ', depth * 4);
                str.Append(elemName + ": " + elem.TagName + "(Level " + depth + ")");
                returnStr.AppendLine(str.ToString());

                if (elem.CanHaveChildren)
                {
                    PrintDom(elem.Children, returnStr, depth + 1);
                }

                str.Remove(0, str.Length);
            }

            return (returnStr.ToString());
        }
 public static HtmlElement getHtmlElement(HtmlElementCollection collection, string attr, string value)
 {
     HtmlElement[] elementArray =  getHtmlElement(collection, new string[] { attr }, new string[] { value });
     if (elementArray.Length == 0)
     {
         return null;
     }
     return elementArray[0];
 }
Example #4
0
 protected HtmlElement getElByIndex(string tagName, string index, HtmlElementCollection m_tags)
 {
     HtmlElement  m_curr = null;
     int iCur = 0;
     foreach(HtmlElement e in m_tags) {
         if (e.TagName == tagName)  {
             int num = Int32.Parse(index);
             if(iCur == num) {
                 m_curr = e;
                 break;
             }
             else iCur++;
         }
     }
     return m_curr;
 }
        /// <summary>
        /// Recursive function to add the DOM element to the treeview
        /// </summary>
        /// <param name="currentEle">collection of elements</param>
        /// <param name="tn">tree node. currently not used</param>
        /// <remarks>The treenode was used prior to placing this function on its own thread
        /// at that point, I was nesting the nodes. right now, i am having trouble doing this across threads</remarks>
        private static void FillDomTree(HtmlElementCollection currentEle, TreeNode tn, int nodeTracker)
        {
            foreach (HtmlElement element in currentEle)
            {
                TreeNode tempNode;

                var tag = element.TagName;

                if (tag.CompareTo("!") == 0)
                {
                    tempNode = tn.Nodes.Add("<Comment>");
                }
                else
                {
                    string sNodeText = "<" + element.TagName;
                    if ((element.Name != null ) && (element.Name.Length > 0))
                        sNodeText += " name=\"" + element.Name + "\"";
                    if ((element.Id != null) && (element.Id.Length > 0))
                        sNodeText += " id=\"" + element.Id + "\"";
                    sNodeText += ">";
                    tempNode = tn.Nodes.Add(sNodeText);
                    int iInnerTextLength = element.InnerText != null ? element.InnerText.Length : 0;
                    if (iInnerTextLength > 0)
                    {
                        string sInnerText;
                        if (iInnerTextLength > 20)
                            sInnerText = element.InnerText.Substring(0, 20) + "...";
                        else
                            sInnerText = element.InnerText;
                        tempNode.Nodes.Add("InnerText=\"" + sInnerText + "\"");
                    }
                }

                /** a counter to keep track of the absolute index of the nodes. Stuffing value into tag **/
                tempNode.Tag = nodeTracker++;

                /** over and over and over and over **/
                FillDomTree(element.Children, tempNode, nodeTracker);
            }
        }
 public static HtmlElement[] getHtmlElement(HtmlElementCollection collection, string[] attrs, string[] values)
 {
     if (attrs.Length != values.Length)
     {
         return null;
     }
     List<HtmlElement> list = new List<HtmlElement>();
     foreach (HtmlElement element in collection)
     {
         bool flag = true;
         for (int i = 0; i < attrs.Length; i++)
         {
             if (element.GetAttribute(attrs[i]).IndexOf(values[i]) == -1)
             {
                 flag = false;
             }
         }
         if (flag)
         {
             list.Add(element);
         }
     }
     return list.ToArray();
 }
Example #7
0
        private void web_DocumentCompleted(object sender, sy.WebBrowserDocumentCompletedEventArgs e)
        {
            sy.WebBrowser web = (sy.WebBrowser)sender;
            if (web.Document != null)
            {
                sy.HtmlElementCollection tbs = web.Document.GetElementsByTagName("TABLE");
                if (tbs.Count == 8)
                {
                    sy.HtmlElementCollection trs = tbs[7].GetElementsByTagName("TR");

                    ArrayList list = new ArrayList();
                    for (int j = 1; j < trs.Count; j++)
                    {
                        sy.HtmlElementCollection tds = trs[j].GetElementsByTagName("TD");
                        if (tds.Count == 13)
                        {
                            var bd = new BaseDetail
                            {
                                Time = Pfun.StringtoDatetime1(tds[0].InnerText.Trim(), "MM/dd/yyyy").ToString("yyyyMMdd"),
                                Kp   = Pfun.Stringtodouble1(tds[1].InnerText.Trim()),
                                Zg   = Pfun.Stringtodouble1(tds[2].InnerText.Trim()),
                                Zd   = Pfun.Stringtodouble1(tds[3].InnerText.Trim()),
                                Sp   = Pfun.Stringtodouble1(tds[4].InnerText.Trim()),
                                Cjl  = Pfun.Stringtodouble1(tds[5].InnerText.Replace(",", "").Trim()),
                                Cjje = Pfun.Stringtodouble1(tds[6].InnerText.Replace(",", "").Trim()),
                                Sdl  = Pfun.Stringtodouble1(tds[7].InnerText.Trim()),
                                Sdbl = Pfun.Stringtodouble1(tds[8].InnerText.Replace("%", "").Trim()),
                                S    = Pfun.Stringtoint1(tds[9].InnerText),
                                Gdc  = Pfun.Stringtodouble1(tds[10].InnerText.Replace("%", "").Trim()),
                                Sz   = Pfun.Stringtodouble1(tds[11].InnerText.Trim()),
                                Szl  = Pfun.Stringtodouble1(tds[12].InnerText.Replace("%", "").Trim()),
                            };
                            Detail.Add(bd);

                            list.Add("insert into BaseData_" + Name + "(tradetime,kpjg,zgjg,zdjg,spjg,cjl,cjje,sd,sdbl) " +
                                     "values ('" + bd.Time + "'," + bd.Kp +
                                     "," + bd.Zg + "," + bd.Zd +
                                     "," + bd.Sp + "," + bd.Cjl + "," + bd.Cjje + "," + bd.Sdl + "," + bd.Sdbl + ")");
                        }
                    }

                    if (list.Count > 0)
                    {
                        if (!DbHelperSqLite.Exists("select count(*) from sqlite_master where type='table' and name='BaseData_" + Name + "'"))
                        {
                            string tableText = (string)DbHelperSqLite.GetSingle("select table_text from need_createtable where Table_name = 'BaseData' Limit 1");
                            if (tableText == null)
                            {
                                Log.WriteLog("need_createtable表中没有BaseData_表的创建代码");
                                return;
                            }
                            tableText = tableText.Replace("XX", Name);
                            DbHelperSqLite.ExecuteSql(tableText);
                        }
                        DbHelperSqLite.ExecuteSqlTran(list);

                        if (!DbHelperSqLite.Exists("select count(*) from sqlite_master where type='table' and name='BaseDataReceived_" + Name + "'"))
                        {
                            string tableText = (string)DbHelperSqLite.GetSingle("select table_text from need_createtable where Table_name = 'BaseDataReceived' Limit 1");
                            if (tableText == null)
                            {
                                Log.WriteLog("need_createtable表中没有BaseDataReceived表的创建代码");
                                return;
                            }
                            tableText = tableText.Replace("XX", Name);
                            DbHelperSqLite.ExecuteSql(tableText);
                        }
                        if (DbHelperSqLite.Exists("select count(*) from BaseDataReceived_" + Name))
                        {
                            DbHelperSqLite.ExecuteSql("update BaseDataReceived_" + Name + " set status = 1 where tradedate  ='" + DateTime.Now.ToString("yyyyMMdd") + "'");
                        }
                        else
                        {
                            DbHelperSqLite.ExecuteSql("insert into BaseDatareceived_" + Name + "(tradedate,status) values('" + DateTime.Now.ToString("yyyyMMdd") + "',1) ");
                        }
                        Log.WriteLog("股票【" + Name + "】的数据获取成功");
                    }
                }
            }
        }
Example #8
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            switch (step)
            {
                case 1:

                    step = 0;
                    toolStep.Text = "Étape : 1";
                    hotmailer.webBrowser1.Navigate("http://google.com");
                    hotmailer.Show();
                    step = 2;

                    break;

                case 2:

                    step = 0;
                    toolStep.Text = "Étape : 2";

                    identity = hotmailer.webBrowser1.Document.GetElementById("identity");

                    /*
                     * Modifications for GAF
                     *
                     */

                    SendKeys.Send("test");
                    ClearCookies();
                    WebBrowserHelper.ClearCache();
                    break;

                    if (identity != null)
                    {
                        // Entre mot de passe
                        identity.Focus();

                        SendKeys.Send("loubna");

                        if (identity.GetAttribute("value") != "loubna")
                        {
                            // La page n'était pas chargée
                            step = 2;
                            return;
                        }

                        // Entre code de campagne.
                        campaignCode = hotmailer.webBrowser1.Document.GetElementById("campaignCode");
                        campaignCode.Focus();

                        SendKeys.SendWait(codeDeCampagne);

                        while (campaignCode.GetAttribute("value") != codeDeCampagne)
                        {
                            campaignCode.Focus();

                            // Problème quelconque: on efface l'input et recommence.
                            while (campaignCode.GetAttribute("value") != "")
                            {
                                SendKeys.SendWait("{BACKSPACE}");
                            }

                            SendKeys.SendWait(codeDeCampagne);
                        }

                        // Clique sur une DIV invisble ayant onclick="next();": simule un "{ENTER}"
                        pressEnter = hotmailer.webBrowser1.Document.GetElementById("pressEnter");
                        pressEnter.InvokeMember("click");

                        step = 3;
                    }
                    else
                    {
                        step = 2;
                    }

                    break;

                case 3:

                    step = 0;
                    toolStep.Text = "Étape : 3";

                    // Collecte le compte Yahoo
                    address = hotmailer.webBrowser1.Document.GetElementById("address");
                    strAddress = address.GetAttribute("value");

                    if (strAddress == "")
                    {
                        // La page n'était pas chargée
                        step = 3;
                        return;
                    }

                    // Collecte le mot de passe
                    password = hotmailer.webBrowser1.Document.GetElementById("password");
                    strPassword = password.GetAttribute("value");

                    // Collecte le récipient
                    recipient = hotmailer.webBrowser1.Document.GetElementById("recipient");
                    strRecipient = recipient.GetAttribute("value");

                    // Collecte le sujet
                    subject = hotmailer.webBrowser1.Document.GetElementById("subject");
                    strSubject = subject.GetAttribute("value");

                    username = webBrowser1.Document.GetElementById("username");

                    if (username == null)
                    {
                        // Déjà loggé
                        hotmailer.Hide();
                        step = 6;
                    }
                    else
                    {
                        step = 4;
                    }

                    break;

                case 4:

                    step = 0;
                    toolStep.Text = "Étape : 4";
                    hotmailer.Hide();

                    // Injecte le nom de compte Yahoo
                    username = webBrowser1.Document.GetElementById("username");

                    if (username != null)
                    {
                        username.InvokeMember("focus");
                        SendKeys.SendWait(strAddress);

                        webBrowser1.Document.ExecCommand("SelectAll", true, null);
                        webBrowser1.Document.ExecCommand("Copy", true, null);

                        if (Clipboard.GetText() != strAddress)
                        {
                            // L'adresse n'a pas bien ete transmise
                            SendKeys.SendWait("^{BACKSPACE}");
                            step = 4;
                            break;
                        }
                        else
                        {
                            SendKeys.SendWait("{TAB}");

                            webBrowser1.Document.ExecCommand("SelectAll", true, null);
                            SendKeys.SendWait("^{BACKSPACE}");

                            // Injecte le mot de passe
                            passwd = webBrowser1.Document.GetElementById("passwd");
                            passwd.InvokeMember("focus");
                            SendKeys.SendWait(strPassword);

                            step = 5;
                        }
                    }
                    else
                    {
                        if (webBrowser1.Document.GetElementById("compose_button_label") != null)
                        {
                            // Login déjà fait. Page chargée.
                            step = 6;
                        }
                        else
                        {
                            step = 4;
                        }
                    }

                    break;

                case 5:

                    step = 0;
                    toolStep.Text = "Étape : 5";

                    loginCounter = 0;

                    webBrowser1.Document.ExecCommand("SelectAll", true, null);
                    webBrowser1.Document.ExecCommand("Copy", true, null);

                    if (Clipboard.GetText() == strAddress || Clipboard.GetText().IndexOf("●") != -1)
                    {
                        // Nous sommes bien dans un input dans contenant l'adresse ou le mot de passe
                        SendKeys.SendWait("{ENTER}");
                        step = 6;
                    }
                    else
                    {
                        step = 4;
                    }

                    // Envoie la form (ID du bouton connection: ".save")
                    /*dotSave = webBrowser1.Document.GetElementById(".save");

                    if (dotSave != null)
                    {
                        dotSave.InvokeMember("click");
                        loginCounter = 0;
                        step = 6;
                    }
                    else
                    {
                        step = 5;
                    }*/

              break;

                case 6:

                    step = 0;
                    toolStep.Text = "Étape : 6";

                    if (webBrowser1.Document.GetElementById("compose_button_label") != null)
                    {
                        // Injecte N pour ouvrir l'onglet nouveau message
                        SendKeys.SendWait("n");

                        textAreas = webBrowser1.Document.GetElementsByTagName("textarea");
                        if (textAreas.Count < 3)
                        {
                            step = 6;
                        }
                        else
                        {
                            step = 7;
                        }
                    }
                    else
                    {
                        loginCounter++;

                        if (loginCounter >= 5)
                        {
                            // Apres 5 tentatives, re-login
                            step = 4;
                        }
                        else{
                            step = 6;
                        }
                    }

                    break;

                case 7:

                    step = 0;
                    toolStep.Text = "Étape : 7";

                    textAreas = null;
                    textAreas = webBrowser1.Document.GetElementsByTagName("textarea");

                    // Parcours tous les éléments TextArea pour trouver l'ID du champ "À:" (qui est aléatoire mais commence toujours par "Toi")
                    for (int i = 0; i <= textAreas.Count - 1; i++)
                    {
                        aID = textAreas[i].GetAttribute("id");
                        if (aID.Length > 3)
                        {
                            if (aID.Substring(0, 3) == "Toi")
                            {
                                aArea = webBrowser1.Document.GetElementById(aID);
                                aArea.InvokeMember("focus");
                                SendKeys.SendWait(strRecipient);

                                step = 8;
                                break;
                            }
                        }
                    }

                    break;

                case 8:

                    step = 0;
                    toolStep.Text = "Étape : 8";

                    // Vérifie que "À:" contient la bonne adresse
                    aArea = webBrowser1.Document.GetElementById(aID);
                    aArea.InvokeMember("focus");

                    webBrowser1.Document.ExecCommand("SelectAll", true, null);
                    webBrowser1.Document.ExecCommand("Copy", true, null);
                    //webBrowser1.Document.ExecCommand("Unselect", true, null);

                    if (Clipboard.GetText() != strRecipient)
                    {
                        // Échec: input récipient vide ou incomplet
                        aArea.InvokeMember("focus");
                        SendKeys.SendWait(strRecipient);
                        step = 8;
                    }
                    else
                    {
                        step = 9;
                    }

                    break;

                case 9:

                    step = 0;
                    toolStep.Text = "Étape : 9";

                    // TAB à l'input "Sujet", au cas ou Focus() fail
                    SendKeys.SendWait("{TAB}");
                    SendKeys.SendWait("{TAB}");

                    inputs = webBrowser1.Document.GetElementsByTagName("input");

                    // Parcours tous les éléments Input pour trouver l'ID du champ "Objet:" (qui est aléatoire mais commence toujours par "Subject")
                    for (int i = 0; i <= inputs.Count - 1; i++)
                    {
                        subjectID = inputs[i].GetAttribute("id");
                        if (subjectID.Length > 6)
                        {
                            if (subjectID.Substring(0, 7) == "Subject")
                            {
                                input = webBrowser1.Document.GetElementById(subjectID);
                                input.InvokeMember("focus");
                                SendKeys.SendWait(strSubject);
                                step = 10;
                                break;
                            }
                        }
                    }

                    break;

                case 10:

                    step = 0;
                    toolStep.Text = "Étape : 10";

                    // Vérifie que "Objet:" contient le bon message
                    input = webBrowser1.Document.GetElementById(subjectID);
                    input.InvokeMember("focus");

                    webBrowser1.Document.ExecCommand("SelectAll", true, null);
                    webBrowser1.Document.ExecCommand("Copy", true, null);
                    //webBrowser1.Document.ExecCommand("Unselect", true, null);

                    if (Clipboard.GetText() != strSubject)
                    {
                        // Échec: input sujet vide ou incomplet
                        input.InvokeMember("focus");
                        SendKeys.SendWait(strSubject);
                        step = 10;
                    }
                    else
                    {
                        // Tab à la textArea du message
                        SendKeys.SendWait("{TAB}");

                        hotmailer.Show();
                        step = 11;
                    }

                    break;

                case 11:

                    step = 0;
                    toolStep.Text = "Étape : 11";

                    // Focus sur l'IFRAME.
                    subject = hotmailer.webBrowser1.Document.GetElementById("subject");
                    subject.Focus();
                    SendKeys.SendWait("{TAB}");

                    // Vide le clipboard
                    Clipboard.Clear();

                    // CTRL + A, CTRL + C pour transférer le message au clipboard
                    hotmailer.webBrowser1.Document.ExecCommand("SelectAll", true, null);
                    hotmailer.webBrowser1.Document.ExecCommand("Copy", true, null);

                    if (Clipboard.GetText().IndexOf("Si vous souhaitez ne plus recevoir cette newsletter") == -1)
                    {
                        // Échec: IFRAME non chargé, clipboard vide ou incomplet
                        step = 11;
                    }
                    else
                    {
                        hotmailer.webBrowser1.Document.ExecCommand("Unselect", true, null);

                        hotmailer.Hide();
                        step = 12;
                    }

                    break;

                case 12:

                    step = 0;
                    toolStep.Text = "Étape : 12";

                    // Injecte le message
                    webBrowser1.Document.ExecCommand("Paste", true, null);

                    // Vérifie que le champ du message n'est pas vide
                    /*input = webBrowser1.Document.GetElementById(subjectID);
                    input.InvokeMember("focus");*/
                    SendKeys.SendWait("{TAB}");

                    webBrowser1.Document.ExecCommand("SelectAll", true, null);
                    webBrowser1.Document.ExecCommand("Copy", true, null);
                    webBrowser1.Document.ExecCommand("Unselect", true, null);

                    if (Clipboard.GetText().IndexOf("Si vous souhaitez ne plus recevoir cette newsletter") == -1)
                    {
                        // Échec: message absent ou incomplet
                        step = 12;
                    }
                    else
                    {
                        // Remonte à "Cc:"
                        SendKeys.SendWait("+{TAB}");
                        SendKeys.SendWait("+{TAB}");
                        // Injecte un espace dans "Cc:" pour pouvoir vérifier s'il ne contient que cela (s'il est vide, CTRL+A CTRL+C ne l'indique pas)
                        SendKeys.SendWait(" ");

                        step = 13;
                    }

                    break;

                case 13:

                    step = 0;
                    toolStep.Text = "Étape : 13";

                    isCcEmpty();

                    // Remonte à "À:" (SHIT+TAB) au cas où focus fail
                    SendKeys.SendWait("+{TAB}");

                    step = 14;

                    break;

                case 14:

                    step = 0;
                    toolStep.Text = "Étape : 14";

                    isRecipientValid();

                    // Descend à "Sujet:" (TAB) au cas où focus fail
                    SendKeys.SendWait("{TAB}");
                    SendKeys.SendWait("{TAB}");

                    step = 15;

                    break;

                case 15:

                    step = 0;
                    toolStep.Text = "Étape : 15";
                    isSubjectValid();
                    step = 16;

                    break;

                case 16:

                    step = 0;
                    toolStep.Text = "Étape : 16";

                    // Envoie le message (CTRL + ENTER)
                    SendKeys.SendWait("^{ENTER}");

                    // Clique a une certaine coordonnée, là où le message de bienvenue de Yahoo peut apparaître
                    //clickOnWebBrowser(535, 450);

                    step = 17;

                    break;

                case 17:

                    step = 0;

                    captchaCounter = 0;
                    toolStep.Text = "Étape : 17";

                    // Vérification de captcha
                    // Si 3 inputs ont comme ID "firstName[...]", le message est envoyé.

                    messageSent = webBrowser1.Document.GetElementsByTagName("input");

                    for (int i = 0; i <= messageSent.Count - 1; i++)
                    {
                        messageSentID = messageSent[i].GetAttribute("id");

                        if (messageSentID.IndexOf("firstName") != -1)
                        {
                            captchaCounter++;
                        }

                        if (messageSentID.IndexOf("captcha_resp") != -1)
                        {
                            // Captcha!
                            step = 19;
                            goto Fin;
                        }
                    }

                    if (captchaCounter >= 3)
                    {
                        // Message envoyé, ferme l'onglet (CTRL+BACKSPACE)
                        step = 18;
                        SendKeys.Send("^{BACKSPACE}");
                    }
                    else
                    {
                        // "Envoi du message..."
                        step = 17;
                    }

            Fin:

                    break;

                case 18:

                    step = 0;
                    toolStep.Text = "Étape : 18";

                    // Génère prochain mail.
                    pressEnter = hotmailer.webBrowser1.Document.GetElementById("pressEnter");

                    if (pressEnter != null)
                    {
                        hotmailer.Show();
                        pressEnter.InvokeMember("click");

                        step = 20;
                    }
                    else
                    {
                        step = 18;
                    }

                    break;

                case 19:

                    step = 0;
                    toolStep.Text = "Étape : 19";

                    // Reset le compteur de /tool
                    pressEscape = hotmailer.webBrowser1.Document.GetElementById("pressEscape");

                    if (pressEscape != null)
                    {
                        hotmailer.Show();
                        pressEscape.InvokeMember("click");

                        // Génère un nouveau compte Yahoo
                        pressEnter.InvokeMember("click");

                        step = 20;
                    }
                    else
                    {
                        step = 19;
                    }

                    break;

                case 20:

                    step = 0;
                    toolStep.Text = "Étape : 20";

                    // Attend que le récipient ai changé (page chargée)
                    recipient = hotmailer.webBrowser1.Document.GetElementById("recipient");

                    string tmpRecipient = recipient.GetAttribute("value");

                    if (tmpRecipient != strRecipient && tmpRecipient != null && tmpRecipient != "")
                    {
                        //iteration++;

                        address = hotmailer.webBrowser1.Document.GetElementById("address");

                        string tmpAddress = address.GetAttribute("value");

                        if (tmpAddress != strAddress)
                        {
                            iteration++;

                            strAddress = tmpAddress;
                            strRecipient = tmpRecipient;

                            // Collecte le mot de passe
                            password = hotmailer.webBrowser1.Document.GetElementById("password");
                            strPassword = password.GetAttribute("value");

                            // Efface les cookies
                            ClearCookies();

                            // Efface le cache
                            WebBrowserHelper.ClearCache();

                            // Ferme la session
                            InternetSetOption(IntPtr.Zero, INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0);

                            // Rafraîchit la page
                            webBrowser1.Document.Window.Navigate("http://login.yahoo.com/config/login_verify2?.intl=fr&.src=ym");
                            //webBrowser1.Document.Window.Navigate("http://mail.yahoo.fr");

                            step = 4;
                        }
                        else
                        {
                            hotmailer.Hide();
                            strRecipient = tmpRecipient;

                            step = 6;
                            //iteration++;
                        }
                    }
                    else
                    {
                        step = 20;
                    }

                    break;
            }
        }
Example #9
0
        private void isCcEmpty()
        {
            // Le message se retrouve parfois dans le champ "Cc:": on s'assure donc qu'il reste vide

            HtmlElementCollection textAreas = null;
            textAreas = webBrowser1.Document.GetElementsByTagName("textarea");

            // Parcours tous les éléments TextArea pour trouver l'ID du champ "Cc:" (qui est aléatoire mais commence toujours par "Cc")
            for (int i = 0; i <= textAreas.Count - 1; i++)
            {
                ccID = textAreas[i].GetAttribute("id");
                if (ccID.Length > 2)
                {
                    if (ccID.Substring(0, 2) == "Cc")
                    {
                        HtmlElement ccArea = webBrowser1.Document.GetElementById(ccID);
                        ccArea.InvokeMember("focus");

                        string previousClipBoard = Clipboard.GetText();

                        webBrowser1.Document.ExecCommand("Unselect", true, null);
                        webBrowser1.Document.ExecCommand("SelectAll", true, null);
                        webBrowser1.Document.ExecCommand("Copy", true, null);

                        if (Clipboard.GetText() != " ")
                        {
                            // Efface le contenu de "Cc:"
                            SendKeys.SendWait("{BACKSPACE}");

                            // Vérifie s'il y a eu un changement, sinon on assume que l'input est vide (sans espace)
                            webBrowser1.Document.ExecCommand("Unselect", true, null);
                            webBrowser1.Document.ExecCommand("SelectAll", true, null);
                            webBrowser1.Document.ExecCommand("Copy", true, null);
                            if (Clipboard.GetText() == previousClipBoard)
                            {
                                break;
                            }

                            isCcEmpty();
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }
 public List<HtmlElement> Select(HtmlElementCollection elements)
 {
     var list = new List<HtmlElement>();
     foreach (HtmlElement item in elements)
     {
         list.Add(item);
     }
     return this.Select(list);
 }
Example #11
0
		private void ProcessElement(HtmlElementCollection elements, TreeNodeCollection nodes)
		{
			// Scan through the collection of elements.
			foreach (HtmlElement element in elements)
			{
				// Create a new node that shows the tag name.
				TreeNode node = new TreeNode("<" + element.TagName + ">");
				nodes.Add(node);
				
				if ((element.Children.Count == 0) && (element.InnerText != null))
				{
					// If this element doesn't contain any other elements, add
					// any leftover text content as a new node.
					node.Nodes.Add(element.InnerText);
				}
				else
				{
					// If this element contains other elements, process them recursively.
					ProcessElement(element.Children, node.Nodes);
				}
			}
		}
        private IList<string> GetInnerHtmlByClassName(HtmlElementCollection htmlCollection, string className)
        {
            if (htmlCollection == null)
                return null;

            IList<string> objects = new List<string>();

            foreach (HtmlElement link in htmlCollection)
                if (link.GetAttribute("className") == className)
                    objects.Add(link.InnerHtml);

            return objects;
        }
Example #13
0
 /// <summary>
 /// 使用JQuery语法筛选元素
 /// </summary>
 /// <param name="elements"></param>
 /// <param name="selector"></param>
 /// <returns></returns>
 public static List <HtmlElement> JQuerySelect(this HtmlElementCollection elements, string selector)
 {
     return(elements.ToList().JQuerySelect(selector));
 }
Example #14
0
 private HtmlElement GetElementByClass(HtmlElementCollection hec, string classname)
 {
     lock(hec)
         try
         {
             foreach (HtmlElement h in hec)
             {
                 if (h.GetAttribute("className") == classname)
                     return h;//.InvokeMember("click");
                 else
                 {
                     string cl = h.GetAttribute("className");
                     cl = null;
                 }
                 if (h.CanHaveChildren)
                 {
                     HtmlElement res = null;
                     res = GetElementByClass(h.Children, classname);
                     if (res != null)
                         return res;
                 }
             }
         }
         catch {; }
     return null;
 }
 private void ProcessElement1(HtmlElementCollection elements, TreeNodeCollection nodes)
 {
     foreach (HtmlElement element in elements)
     {
         TreeNode node = new TreeNode("<" + element.TagName + ">");
         nodes.Add(node);
         if ((element.Children.Count == 0) && (element.TagName != null))
         {
             node.Nodes.Add(element.OuterText);
         }
         else
         {
             ProcessElement1(element.Children, node.Nodes);
         }
     }
 }
Example #16
0
 private int searchitem(string attrname, string matchstr, ref HtmlElementCollection hecollection)
 {
     if (attrname == "class") attrname = "classname";
     if (attrname == "for") attrname = "htmlfor";
     for (int i = 0; i < hecollection.Count; i++)
     {
         if (hecollection[i].GetAttribute(attrname) == matchstr)
             return i;
     }
     return hecollection.Count;
 }
Example #17
0
        private void loop(HtmlElementCollection list)
        {
            foreach (HtmlElement item in list)
            {
                if (item.InnerText != null && item.InnerText == "思科九年")
                {
                    listBox1.Items.Add("Level:   " + i.ToString());
                    i++;
                    listBox1.Items.Add("#### ID: " + item.Id);
                    listBox1.Items.Add("#### Name: " + item.Name);
                    listBox1.Items.Add("#### TabIndex: " + item.TabIndex);
                    listBox1.Items.Add("#### TagName: " + item.TagName);
                    listBox1.Items.Add("#### CanHaveChildren: " + item.CanHaveChildren);
                    listBox1.Items.Add("#### OuterHtml: " + item.OuterHtml);
                    listBox1.Items.Add("#### OuterText: " + item.OuterText);
                    listBox1.Items.Add("#### GetAttribute(\"class\"): " + item.GetAttribute("class"));
                    listBox1.Items.Add("");

                }
                loop(item.Children);

            }
            //listBox1.Items.Add("");
            //listBox1.Items.Add("");
            //listBox1.Items.Add("");
            //listBox1.Items.Add("");
            //listBox1.Items.Add("");
            //listBox1.Items.Add("");
            //listBox1.Items.Add("Complete!!!!!!!!!!!!!!!!!!!!!!");
            //listBox1.Items.Add("");
            //listBox1.Items.Add("");
            //listBox1.Items.Add("");
            //listBox1.Items.Add("");
            //listBox1.Items.Add("");
            //listBox1.Items.Add("");
        }
Example #18
0
 private void ToList(HtmlElementCollection collection, List<String> list)
 {
     System.Collections.IEnumerator it = collection.GetEnumerator();
     while (it.MoveNext())
     {
         HtmlElement htmlElement = (HtmlElement)it.Current;
         list.Add(htmlElement.OuterHtml);
     }
 }
Example #19
0
 public static void SetAllWebItemSelf(HtmlElementCollection items)
 {
     try
     {
         foreach (HtmlElement item in items)
         {
             if (item.TagName.ToLower().Equals("iframe", StringComparison.OrdinalIgnoreCase) == false)
             {
                 try
                 {
                     item.SetAttribute("target", "_self");
                 }
                 catch
                 { }
             }
             else
             {
                 try
                 {
                     HtmlElementCollection fitems = item.Document.Window.Frames[item.Name].Document.All;
                     SetAllWebItemSelf(fitems);
                 }
                 catch
                 { }
             }
         }
     }
     catch
     {
     }
 }
        private static List<HtmlElement> GetElementsByAttribute(HtmlElementCollection elemColl, string attributeName, string value, Int32 depth)
        {
            List<HtmlElement> result = new List<HtmlElement>();
            foreach (HtmlElement e in elemColl)
            {
                if (e.OuterHtml != null && (e.OuterHtml.ToLower().Contains(string.Format("{0}='{1}'", attributeName.ToLower(), value.ToLower()))
                  || e.OuterHtml.ToLower().Contains(string.Format("{0}=\"{1}\"", attributeName.ToLower(), value.ToLower()))
                  || e.OuterHtml.ToLower().Contains(string.Format("{0}={1}", attributeName.ToLower(), value.ToLower()))))
                    result.Add(e);

                if (e.CanHaveChildren)
                {
                    GetElementsByAttribute(e.Children, attributeName, value, depth + 1);
                }

            }
            return result;
        }
        private static void GetHtmlEntriesFromSwedBank(
            HtmlElementCollection htmlElements, SortedList kontoEntries, SortedList newKontoEntries)
        {
            // Spara en batch, dyker det upp dubletter i samma, så ska de ses som unika
            var newBatchOfKontoEntriesAlreadyRed = EntryAdder.GetNewBatchOfKontoEntriesAlreadyRed(kontoEntries, newKontoEntries);

            var first = true;
            foreach (HtmlElement htmlElement in htmlElements)
            {
                // Skip first, column descriptons
                if (first)
                {
                    first = false;
                }
                else
                {
                    if (htmlElement.Children.Count < 2)
                    {
                        continue;
                    }

                    if (htmlElement.InnerText.StartsWith("Föregående"))
                    {
                        break;
                    }

                    // Lägg till ny
                    EntryAdder.AddNewEntryFromStringArray(
                        GetSwedBankTableRow(htmlElement),
                        kontoEntries,
                        newKontoEntries,
                        newBatchOfKontoEntriesAlreadyRed);
                }
            }
        }
 private List<string> ExtractUrls(HtmlElementCollection elements, string tag, string baseUrl)
 {
     List<string> urls = new List<string>();
     foreach (HtmlElement element in elements)
     {
         try
         {
             string url = element.GetAttribute(tag);
             if (!url.Contains(baseUrl)) url = baseUrl + url;
             url = url.Replace("about:", "");      // BIG HACK - se for IE, diz ao IE que vá dar uma curva... :(
             Uri temp;
             if (Uri.TryCreate(url, UriKind.Absolute, out temp) && !urls.Contains(url)) urls.Add(url);
         }
         catch { }
     }
     return urls;
 }
Example #23
0
        // callback function to get the content of page in the WebBrowser control
        public void getHtmlResult(int count)
        {
            // unequal means the content is not stable
            if (owner.navigationCounter != count)
            {
                return;
            }

            // get HTML content
            owner.htmlResult = owner.ieBrowser.DocumentText;

            forms.HtmlDocument doc = owner.ieBrowser.Document;
            if (doc.Cookie != null)
            {
                // get cookies
                owner.htmlCookieTable = "<table border=1 cellspacing=0 cellpadding=2><tr><th>Name</th><th>Value</th><tr>";
                foreach (string cookie in Regex.Split(doc.Cookie, @";\s*"))
                {
                    string[] arr = cookie.Split(new char[] { '=' }, 2);
                    owner.htmlCookieTable += string.Format("<td>{0}</td><td>{1}</td></tr>", arr[0], (arr.Length == 2) ? arr[1] : "&nbsp;");
                }
                owner.htmlCookieTable += "</table><p />";
            }

            forms.HtmlElementCollection inputs = doc.GetElementsByTagName("INPUT");
            if (inputs.Count != 0)
            {
                // get ids, names, values and types of input elements
                owner.htmlInputTable = "<table border=1 cellspacing=0 cellpadding=2><tr><th>Id</th><th>Name</th><th>Value</th><th>Type</th><tr>";
                foreach (forms.HtmlElement input in inputs)
                {
                    owner.htmlInputTable += string.Format("<td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>", input.GetAttribute("Id"), input.GetAttribute("Name"), input.GetAttribute("Value"), input.GetAttribute("Type"));
                }
                owner.htmlInputTable += "</table><p />";
                owner.htmlInputTable  = owner.htmlInputTable.Replace("<td></td>", "<td>&nbsp;</td>");
            }

            forms.HtmlElementCollection scripts = doc.GetElementsByTagName("SCRIPT");
            if (scripts.Count != 0)
            {
                string vars = string.Empty;
                foreach (forms.HtmlElement script in scripts)
                {
                    if (script.InnerHtml == null)
                    {
                        continue;
                    }

                    foreach (string name in getVariableNames(script.InnerHtml).Split(new char[] { ';' }))
                    {
                        if (name.Trim().Length == 0)
                        {
                            continue;
                        }
                        if (vars.Contains("\"" + name + "\""))
                        {
                            continue;
                        }

                        // one row of the script variable table - <tr>getValue([script variable name]</tr> - getValue() is a script function in JScript.js
                        vars += string.Format("+\"<tr>\"+getValue(\"{0}\")+\"</tr>\"", name);
                    }
                }

                // request script to send back the names, values and types of script variables
                doc.InvokeScript("setTimeout", new object[] { scriptPattern.Replace("{0}", vars.Substring(1)), 10 });
            }
            else
            {
                // set resultEvent to let main thread continue
                owner.resultEvent.Set();
            }
        }