Having just reached the first stage of developing a module for parsing HTML, I thought I'd share a wee snippet for gathering forms from a page to illustrate how the module can be used. The following function:
- Loops through the page content copying everything stored between
<form>...</form>
tags - Loops through each form picking out the pertinent information from
<input>
and<textarea>
tags
Will leave as an exercise as to improve on this:
import <markup>
gather-forms: func [
doc [string!]
/local forms mark extent attributes
][
doc: load-markup doc
forms: collect [
parse doc [
any [
<form> mark: some [
and <form> (print "Warning: cannot gather nested forms") break
|
extent: </form> (keep/only copy/part mark extent) break
|
end (keep/only copy/part mark tail mark)
|
skip
]
|
skip
]
]
]
collect [
foreach form forms [
either map? pick new-line/all form true 1 [
keep make object! [
action: select form/1 "action"
method: any [select form/1 "method" "GET"]
fields: make map! collect [
parse form [
any [
<input> set attributes map! (
keep lock any [select attributes "name" "anon"]
keep select attributes "value"
)
|
<textarea> set attributes map! set text string! (
keep lock any [select attributes "name" "anon"]
keep text
)
|
skip
]
]
]
]
][
print "Warning: form has no attributes"
]
]
]
]
probe gather-forms to string! read https://forum.rebol.info