Exemple #1
0
        public static SubmitValue FromElement(ElementWrapper inputSubmit)
        {
            if (!inputSubmit.HasAttribute("name"))
            {
                return(new SubmitValue());
            }

            var name = inputSubmit.Attribute("name");

            if (!inputSubmit.HasAttribute("value"))
            {
                return(new SubmitValue(name));
            }

            var value = inputSubmit.Attribute("value");

            return(new SubmitValue(name, value));
        }
Exemple #2
0
        public static FormValue FromElement(ElementWrapper element)
        {
            var formValue = new FormValue(element.AttributeOrEmpty("name"));

            formValue.SetDisabled(element.HasAttribute("disabled"));

            switch (element.TagName.ToLower())
            {
            case "input":
                return(FromInput(element, formValue));

            case "textarea":
                return(FromTextArea(element, formValue));

            case "select":
                return(FromSelect(element, formValue));

            default:
                throw new Exception("Unhandled tag: " + element.TagName);
            }
        }
Exemple #3
0
        public static FormValue FromInput(ElementWrapper input, FormValue formValue)
        {
            var type = input.HasAttribute("type") ? input.Attribute("type").ToLower() : "text";

            formValue
            .SetValue(input.HasAttribute("value") ? input.Attribute("value") : null)
            .SetReadonly(input.HasAttribute("readonly"));

            if (type == "checkbox" || type == "radio")
            {
                if (string.IsNullOrEmpty(formValue.Value))
                {
                    formValue.SetValue("on");
                }

                if (!input.HasAttribute("checked"))
                {
                    formValue.SetSend(false);
                }
            }

            return(formValue);
        }
 public TypedForm(ElementWrapper element = null, string method = "", string action = "")
 {
     _element = element;
     SetMethod(method);
     SetAction(action);
 }
Exemple #5
0
        public static TypedForm <T> Scrape <T>(DocumentWrapper doc, string requestUrl, int index)
        {
            var formElements = FindForms(doc, "form");

            if (index > formElements.Count - 1)
            {
                throw new Exception(string.Format("Index '{0}' is too large for collection with '{1}' forms: {2}", index, formElements.Count, ElementWrapper.FormatTags(formElements)));
            }

            return(NewScraper(formElements[index]).Scrape <T>(requestUrl));
        }
Exemple #6
0
 public FormScraper(ElementWrapper element)
 {
     _element = element;
 }
Exemple #7
0
        protected virtual void AddSubmit <T>(TypedForm <T> form, ElementWrapper inputSubmit)
        {
            var submitValue = SubmitValue.FromElement(inputSubmit);

            form.AddSubmitValue(submitValue);
        }