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.
<title>Demo form</title>
<FORM action="http://%%fab-apploc%%/FAB/addalm.py" method="post">
     <TD>House number:</TD>
     <TD><INPUT type="text" size="8" name="almform-house"></TD>
     <TD>Required: The house number part of the alarm address</TD>
     <TD>Street name:</TD>
     <TD><INPUT type="text" size="30" name="almform-street"></TD>
     <TD>Required: The street name part of the alarm address</TD>
<INPUT type="submit" name="almform-submit" value="Add new alarm" ID="updatebutton">
R E B O L [
     Title: "Parse html form for input names"
;; -- Read the html file
HTMLFILE: %rtest-buildmarkup.html
;; -- Pick off the html form embedded somewhere in the html file
HTMLFORM: copy ""
parse HTMLTEXT [thru "<form" copy HTMLFORM to "</form"]
;; -- 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?
parse HTMLFORM [thru "<name=" copy INPUTNAMES to ">"]
;; -- Stop for probing

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



Type the reverse of this captcha text: "t m c"