Home   Archive   Permalink



Parse an html form

I think that one can not claim to be a REBOL programmer unless one can use "parse."
    
Anyway, let's say I have an html page that contains a form, part of which is shown below.
    
I want to do a little experimenting with generating python code, so I want to obtain all the "name" attributes for the "input" items on the form. That would be "almform-house," "almform-street," and "almform-submit."    
    
I am able to parse off the "form" part of the html page, as shown in the sample below. After that, I can't even parse off one name, let alone all of them, and I have no idea how to proceed.    
    
I wonder if someone can offer guidance.
    
Thank you. Code samples follow.
    


Demo form


    


    

    
    
    


    
    
    

    
House number: Required: The house number part of the alarm address
Street name: Required: The street name part of the alarm address
    


    


    
R E B O L [
     Title: "Parse html form for input names"
]
    
;; -- Read the html file
HTMLFILE: %rtest-buildmarkup.html
HTMLTEXT: read HTMLFILE
    
;; -- Pick off the html form embedded somewhere in the html file
HTMLFORM: copy ""
parse HTMLTEXT [thru "    
;; -- Get the names of all input fields...but how?
;; -- Parsing for the name tag returns nothing.
;; -- And how would I do more than one anyway?
INPUTNAMES: copy ""
parse HTMLFORM [thru ""]
    
;; -- Stop for probing
halt

posted by:   Steven White     28-Jun-2018/15:06:04-7:00



inputnames: copy []
parse htmlform [
    any [thru {name="} copy nm to {"} (append inputnames nm)] to end
]
editor inputnames
    
    
(Note that you don't really every need the first parse in your example)

posted by:   Nick     29-Jun-2018/11:03:03-7:00