Exemple #1
0
        private void ParseMethod <T>(IHtmlNodeParser <T> nodeParser)
        {
            var value = nodeParser.GetAttributeValue("method");

            if (!string.IsNullOrEmpty(value) && value.Equals("get"))
            {
                method = HttpVerb.Get;
            }
            else
            {
                method = HttpVerb.Post;
            }
        }
Exemple #2
0
        internal static List <FormField> ParseFormFields <T>(IHtmlNodeParser <T> node)
        {
            var inputs = from input in node.CssSelect("input")
                         let value                       = input.GetAttributeValue("value")
                                                let type = input.GetAttributeValue("type")
                                                           where type != "checkbox" && type != "radio"
                                                           select new FormField
            {
                Name  = input.GetAttributeValue("name"),
                Value = string.IsNullOrEmpty(value) ? input.InnerText : value
            };

            var checkboxes = from input in node.CssSelect("input[type=checkbox]")
                             let value = input.GetAttributeValue("value")
                                         where input.Attributes.AllKeys.Contains("checked")
                                         select new FormField
            {
                Name  = input.GetAttributeValue("name"),
                Value = string.IsNullOrEmpty(value) ? input.InnerText : value
            };

            var radios = from input in node.CssSelect("input[type=radio]")
                         let value = input.GetAttributeValue("value")
                                     where input.Attributes.AllKeys.Contains("checked")
                                     select new FormField
            {
                Name  = input.GetAttributeValue("name"),
                Value = string.IsNullOrEmpty(value) ? input.InnerText : value
            };

            var selects = from @select in node.CssSelect("select")
                          let name = @select.GetAttributeValue("name")
                                     let option =
                @select.CssSelect("option").FirstOrDefault(o => o.Attributes["selected"] != null) ??
                @select.CssSelect("option").FirstOrDefault()
                let value = option.GetAttributeValue("value")
                            select new FormField
            {
                Name  = name,
                Value = string.IsNullOrEmpty(value) ? option.InnerText : value
            };

            return(inputs.Concat(selects).Concat(checkboxes).Concat(radios).ToList());
        }
Exemple #3
0
 private void ParseAction <T>(IHtmlNodeParser <T> nodeParser)
 {
     action = nodeParser.GetAttributeValue("action");
 }
Exemple #4
0
 /// <summary>
 /// Add a new parser to the converter
 /// </summary>
 /// <param name="instance">An instance of the parser to add</param>
 public void AddParser(IHtmlNodeParser instance) => Parsers.Insert(0, instance);
Exemple #5
0
 private void Initialize <T>(IHtmlNodeParser <T> nodeParser)
 {
     FormFields = ParseFormFields(nodeParser);
     ParseAction(nodeParser);
     ParseMethod(nodeParser);
 }