HELP HELP PLEASE HELP

B

beth

i have written a slighly bastardized version of the class web page
which is given as an example of how to use the html tokenizer.

What I've written is:

def parse(host)
dict = { }
@body= host.getHTML()
if !@body
return
end
theTags = ['select','input']
for x in theTags do
tokenizer = HTMLTokenizer.new(@body)
while tag = tokenizer.getTag(x)
name = tag.attr_hash['name']
type = tag.attr_hash['type']
if name != nil then
dict[type]=name
end # if
end# while
end# for x
return dict
end # end parse

My problem is that parse will return all tag attributes of "type" (ie
"checkbox, "button", "hidden") except for those which are of type
"text". I haven't been able to figure out where I'm going wrong.

Beth
 
S

Sean O'Halpin

Have you made sure your text input tags have a name attribute?

require 'html/htmltokenizer'

host =3D Object.new
def host.getHTML
html =3D <<EOT
<form>
<input name=3D"txt1" type=3D"text" value=3D"test" />
<input name=3D"pwd1" type=3D"password" value=3D"test" />
<input name=3D"ck1" type=3D"checkbox" value=3D"1" checked=3D"true"/>
</form>
EOT
end

# Your code follows unchanged

def parse(host)
dict =3D { }
@body=3D host.getHTML()
if !@body
return
end
theTags =3D ['select','input']
for x in theTags do
tokenizer =3D HTMLTokenizer.new(@body)
while tag =3D tokenizer.getTag(x)
name =3D tag.attr_hash['name']
type =3D tag.attr_hash['type']
if name !=3D nil then
dict[type]=3Dname
end # if
end# while
end# for x
return dict
end # end parse

p parse(host)

-- Output --
{"text"=3D>"txt1", "checkbox"=3D>"ck1", "password"=3D>"pwd1"}

Regards,

Sean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

I dont get this. Please help me!! 2
parse page using tokenizer 0
Please Help? 0
Help please 8
Can't solve problems! please Help 0
Code help please 4
Help with code 0
Hello and Help please :-) 1

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top