private static void processaCodigo(List <Folha> lstfolha, Controller ctr, int cod, DateTime periodo)
        {
            ctr.Do(new Redirect(buildUrl(cod)))
            // processa a resposta
            .InspectIf(
                // somente se há dados
                (ctr) =>
            {
                return(ctr.FirstElementOrDefault(By.ClassName("rodape_tabela_resposta")) != null);
            },
                // havendo dados...
                (ctr) =>
            {
                var doc  = HtmlParseHelper.ParseHtmlDocument(ctr.PageSource);
                var hObj = new HObject(doc);

                // //section/div/div/div/
                var painelDados = hObj["section > div > div > div"];

                var folha = preencheFolha(hObj);
                folha.CodigoFuncionario = cod;
                folha.Referencia        = periodo;

                lstfolha.Add(folha);
            })
            // respira ...
            .Sleep(100);
        }
Esempio n. 2
0
        public void Wrappers_HtmlForm_DeepDescendents()
        {
            string html =
                @"<div>
    <form method=""POST"" action=""/"">
        <div class=""left""> 
            <input type=""text"" name=""nTxt1"" value=""vTxt1"">
            <input type=""text"" name=""nTxt2"" value=""vTxt2"">
        </div>
        <div class=""right""> 
            <input type=""text"" name=""nTxt3""   value=""vTxt3"">
            <input type=""hidden"" name=""nTxt4"" value=""vTxt4"">
        </div>
        <select id=""cars"">
            <option value=""car1"">Car 1</option>
            <option value=""car1"">Car 2</option>
        </select>
        <input type=""submit"" id=""btn1"" value=""Insert"">
        <button type=""reset"" class=""button button2"">Reset Form</button>
    </form>
</div>";
            var form = new Tag(HtmlParseHelper.ParseHtmlDocument(html)).SelectTag("//form").Cast <Form>();

            var inputs = form.GetInputs();

            Assert.Equal(5, inputs.Length);
        }
        public override void ParseNode(HtmlNode htmlNode, XElement resultElement, ParseContext parseContext, XElement baseFormattingElement)
        {
            XElement      xElement      = null;
            HtmlAttribute htmlAttribute = htmlNode.Attributes["src"];

            if (htmlAttribute != null)
            {
                MediaItem mediaItem = this.GetMediaItem(htmlAttribute.Value);
                if (mediaItem != null)
                {
                    string text;
                    string text2;
                    StyleParser.ParseDimensions(htmlNode, out text, out text2);
                    if (string.IsNullOrEmpty(text))
                    {
                        text = HtmlParseHelper.ParseDimensionValue(mediaItem.InnerItem["Width"], true);
                    }
                    if (string.IsNullOrEmpty(text2))
                    {
                        text2 = HtmlParseHelper.ParseDimensionValue(mediaItem.InnerItem["Height"], true);
                    }

                    xElement = this.CreateInlineElement(text, text2);
                    XElement content = this.CreateImageElement(htmlNode, mediaItem, parseContext, text, text2);
                    xElement.Add(content);
                }
            }
            if (xElement != null)
            {
                resultElement.Add(xElement);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Parses the Result bytes with HtmlAgilityPack
 /// </summary>
 public HtmlDocument GetDocument()
 {
     if (document == null)
     {
         using MemoryStream ms = new MemoryStream(Result);
         document = HtmlParseHelper.ParseHtmlDocument(ms);
     }
     return(document);
 }
Esempio n. 5
0
        public void Wrappers_HtmlTagCast_Label()
        {
            //var tag = GetTag("//label");
            var tag     = new Tag(HtmlParseHelper.ParseHtmlDocument(LabelTests.html1));
            var lbl     = tag.SelectTag("//label");
            var element = lbl.Cast <Label>();

            Assert.Equal("label", element.TagName);
        }
Esempio n. 6
0
        protected void ParseChildNode(HtmlNode htmlNode, XElement resultElement, ParseContext parseContext, XElement baseFormattingElement)
        {
            if (parseContext.ParseDefinitions.IsEscapedNode(htmlNode))
            {
                return;
            }
            ParseDefinition definition = parseContext.ParseDefinitions[htmlNode];

            if (definition != null)
            {
                Type typeInfo = ReflectionUtil.GetTypeInfo(definition.HtmlParserType);

                if (typeInfo.Name == "CustomHtmlNodeParser")
                {
                    var customParser = CustomHtmlParseHelper.GetParser <CustomHtmlNodeParser>(definition);
                    if (customParser == null)
                    {
                        return;
                    }
                    customParser.SpecialCharacterMapper = SpecialCharacterMapper;
                    customParser.ParseNode(htmlNode, resultElement, parseContext, baseFormattingElement);
                }
                else
                {
                    object parser = CustomHtmlParseHelper.GetParser <HtmlNodeParser>(definition);
                    ((HtmlNodeParser)parser)?.ParseNode(htmlNode, resultElement, parseContext, baseFormattingElement);
                }
            }
            else if (HtmlParseHelper.IsPlainTextNode(htmlNode))
            {
                XCData xcData = new XCData(HtmlEntityHelper.DeEntitize(htmlNode.InnerHtml));

                if (SpecialCharacterMapper != null)
                {
                    SpecialCharacterMapper.ParseSpecialCharacters(xcData.Value, baseFormattingElement, ref resultElement);
                    return;
                }

                if (baseFormattingElement != null)
                {
                    XElement xelement = new XElement(baseFormattingElement);
                    xelement.Add((object)xcData);

                    resultElement.Add((object)xelement);
                }
                else
                {
                    resultElement.Add(xcData);
                }
            }
            else
            {
                XElement formattingElement = StyleParser.GetFormattingElement(htmlNode, baseFormattingElement, true);
                this.ParseChildNodes(htmlNode, resultElement, parseContext, formattingElement);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Parses the Html string with HtmlAgilityPack using specified encoding
        /// </summary>
        /// <param name="SpecifyEncoding">Encoding to use, if NULL instance Encoding will be used. If NULL static DefaultEncoding will be used.</param>
        public HtmlDocument GetDocument(Encoding SpecifyEncoding)
        {
            if (SpecifyEncoding == null)
            {
                SpecifyEncoding = Encoding ?? DefaultEncoding;
            }

            document = HtmlParseHelper.ParseHtmlDocument(HtmlContent(SpecifyEncoding));
            return(document);
        }
Esempio n. 8
0
        protected virtual XElement CreateElement(HtmlNode htmlNode, ParseDefinition definition)
        {
            if (definition == null || !HtmlParseHelper.IsValidTargetTag(definition.XmlTag))
            {
                return((XElement)null);
            }
            XElement element = new XElement((XName)definition.XmlTag);

            this.SetAttributes(element, htmlNode, definition);
            return(element);
        }
Esempio n. 9
0
        private bool PostDataAndLogin()
        {
            HtmlDocument doc = webBrowser.Document;

            if ((null == doc) ||
                !HtmlParseHelper.IsContains(doc.Body.OuterHtml, "Sign in", "i0116", "Keep me signed in"))
            {
                return(false);
            }

            //<div id="idDiv_PWD_UsernameTb" class="cssTextInput"><div style="position: relative; width: 100%; ">
            //<input type="text" name="login" id="i0116" maxlength="113" style="width: 100%; ">

            HtmlElement eleAccount = doc.GetElementById("i0116");

            if (null != eleAccount)
            {
                eleAccount.InnerText = this.CurrentAccount.User;
            }
            //<div id="idDiv_PWD_PasswordTb" class="cssTextInput">
            //<input name="passwd" type="password" id="i0118" maxlength="16" autocomplete="off" style="width: 100%; "></div>
            HtmlElement elePwd = doc.GetElementById("i0118");

            if (null != elePwd)
            {
                elePwd.InnerText = this.CurrentAccount.Password;
            }
            //<input type="checkbox" name="KMSI" id="idChkBx_PWD_KMSI0Pwd" value="1" class="cssCheckbox">
            HtmlElement eleKeep = doc.GetElementById("idChkBx_PWD_KMSI0Pwd");

            if (null != eleKeep)
            {
                eleKeep.SetAttribute("checked", "checked");
            }
            //<input type="submit" name="SI" id="idSIButton9" value="Sign in" style="height: 25px; ">
            HtmlElement btnLogin = doc.GetElementById("idSIButton9");

            if (null != btnLogin)
            {
                LogManager.Info(string.Format("正在查询{0} ,{1}", CurrentAccount.Index, CurrentAccount.EMail));
                btnLogin.InvokeMember("click");
                return(true);
            }
            Navigate();
            return(false);
        }
Esempio n. 10
0
        public virtual void ParseNode(HtmlNode htmlNode, XElement resultElement, ParseContext parseContext, XElement baseFormattingElement)
        {
            XElement element = this.CreateElement(htmlNode, parseContext.ParseDefinitions[htmlNode]);

            resultElement.Add((object)element);
            if (!htmlNode.HasChildNodes)
            {
                return;
            }
            XElement formattingElement = StyleParser.GetFormattingElement(htmlNode, baseFormattingElement, element == null);

            this.ParseChildNodes(htmlNode, element ?? resultElement, parseContext, formattingElement);
            if (element == null)
            {
                return;
            }
            HtmlParseHelper.FixNestedElementsNodes(element);
        }
Esempio n. 11
0
        private void GetLoginState()
        {
            HtmlDocument doc = webBrowser.Document;

            if ((null == doc) || (null == doc.Body))
            {
                this.CurrentAccount.State = LoginState.Unknown;
            }

            string html = doc.Body.OuterHtml;

            // <a name="RpsSignInLink" href="https://live.xbox.com/Account/Signout">Sign Out</a>
            // <span class="spread"><a href="https://live.xbox.com/en-US/Account?xr=mebarnav" >My Account</a></span>
            if (HtmlParseHelper.IsContains(html, "<a name=\"RpsSignInLink\" href=\"https://live.xbox.com/Account/Signout\">Sign Out</a>",
                                           "https://live.xbox.com/Account/Signout", "Sign Out", "https://live.xbox.com/en-US/Account?xr=mebarnav", "My Account"))
            {
                this.CurrentAccount.State = LoginState.LoginSucceed;
            }
            else if (HtmlParseHelper.IsContains(html, "The email address or password is incorrect",
                                                "idTd_Tile_ErrorMsg_Login", "<td class=\"cssError\" id=\"idTd_Tile_ErrorMsg_Login\">"))
            {
                this.CurrentAccount.State = LoginState.LoginFalied;
            }
            else if (HtmlParseHelper.IsContains(html, "That Windows Live ID doesn't exist", "Enter a different ID or get a new one."))
            {
                this.CurrentAccount.State = LoginState.NotExisted;
            }
            else if (HtmlParseHelper.IsContains(html, "We need you to add some security info for your account", "Enter your contact information"))
            {
                this.CurrentAccount.State = LoginState.AdditionalSecurity;
            }
            else if (string.IsNullOrEmpty(html) || HtmlParseHelper.IsContains(html, HttpHelperBase.HTTPERROR,
                                                                              "You've tried to sign in too many times with an incorrect email address or password", "Enter the characters you see",
                                                                              "recaptcha"))
            {
                this.CurrentAccount.State = LoginState.Catpcha;
            }
            else
            {
                this.CurrentAccount.State = LoginState.Unknown;
            }
            autoResetEvent.Set();
        }
Esempio n. 12
0
        private bool Signout()
        {
            HtmlDocument doc = webBrowser.Document;

            if ((null == doc) ||
                !HtmlParseHelper.IsContains(doc.Body.OuterHtml, "Sign Out", "https://live.xbox.com/Account/Signout"))
            {
                return(false);
            }

            if (doc.Body.OuterHtml.Contains("Sign Out"))
            {
                HtmlElement btnSignout = doc.GetElementById("RpsSignInLink");
                if (null != btnSignout)
                {
                    LogManager.Info(string.Format("正在退出{0}", Server.LoginUrl));
                    btnSignout.InvokeMember("click");
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 13
0
        protected virtual void SetAttributes(XElement element, HtmlNode htmlNode, ParseDefinition definition)
        {
            List <ParseAttribute>   applicableAttributes = definition.FindApplicableAttributes(htmlNode);
            HtmlAttributeCollection attributes           = htmlNode.Attributes;

            foreach (ParseAttribute parseAttribute in applicableAttributes)
            {
                try
                {
                    if (!string.IsNullOrEmpty(parseAttribute.XmlAttribute))
                    {
                        string attributeValue = string.Empty;
                        if (!string.IsNullOrEmpty(parseAttribute.HtmlAttribute) && attributes != null && attributes.Contains(parseAttribute.HtmlAttribute))
                        {
                            attributeValue = attributes[parseAttribute.HtmlAttribute].Value;
                            if (attributeValue.Equals(parseAttribute.HtmlDefaultValue))
                            {
                                attributeValue = parseAttribute.XmlDefaultValue;
                            }
                            else if (parseAttribute.HtmlAttribute.Equals("width", StringComparison.InvariantCultureIgnoreCase) || parseAttribute.HtmlAttribute.Equals("height", StringComparison.InvariantCultureIgnoreCase))
                            {
                                attributeValue = HtmlParseHelper.ParseDimensionValue(attributeValue, true);
                            }
                        }
                        if (string.IsNullOrEmpty(attributeValue))
                        {
                            attributeValue = parseAttribute.XmlDefaultValue;
                        }
                        element.SetAttributeValue((XName)parseAttribute.XmlAttribute, (object)attributeValue);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("ParseAttributes", ex);
                }
            }
        }
Esempio n. 14
0
 public static HObject GetHObject(string Html)
 {
     return(new HObject(HtmlParseHelper.ParseHtmlDocument(Html)));
 }
Esempio n. 15
0
 public HtmlDocument GetRootDocument()
 {
     return(HtmlParseHelper.ParseHtmlDocument(TestHelper.BaseHtml()));
 }
Esempio n. 16
0
 public Tag GetTag(string XPath)
 {
     return(new Tag(HtmlParseHelper.ParseHtmlDocument(TestHelper.AllElementsHtml()))
            .SelectTag(XPath));
 }
Esempio n. 17
0
 private bool IsLoginTooMuch(string html)
 {
     return(string.IsNullOrEmpty(html) || HtmlParseHelper.IsContains(html,
                                                                     "You've tried to sign in too many times with an incorrect email address or password",
                                                                     "Enter the characters you see", "recaptcha"));
 }
Esempio n. 18
0
 public static Label build(string Html)
 {
     return(new Tag(HtmlParseHelper.ParseHtmlDocument("<html>" + Html + "</html>")).SelectTag <Label>());
 }