Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WWW:Mechanize , can't understand data structure

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hello,

I seem to be going round in circles trying to understand the mechanize data structure, i've issued the following
Code:
my $mech = [URL unfurl="true"]WWW::Mechanize->new();[/URL]

$mech->agent_alias( 'Windows IE 6' );

$mech->get( $URL );

my @fields = $mech->find_all_inputs;

And here is where I get stuck, I need to find the 'names' of the input fields as the page is that pesky .net and so creates a dynamic field name each time the page loads.

If I use this..
Code:
foreach my $key (@fields){
            print $key . "<br>";
        }
I get ...
HTML::Form::TextInput=HASH(0x31443cc)
HTML::Form::TextInput=HASH(0x31444b0)
HTML::Form::TextInput=HASH(0x31444a4)
HTML::Form::TextInput=HASH(0x3144630)
HTML::Form::TextInput=HASH(0x3144198)
HTML::Form::TextInput=HASH(0x3143fdc)
HTML::Form::TextInput=HASH(0x314457c)

But how do I get access to the hash and find out what the name/value pairs are?

If I try..
Code:
foreach my $key (@fields){
        foreach my $kn( keys $key){
            print $key->{$kn} . "<br>";
        }
}
I get
Type of arg 1 to keys must be hash (not private variable)

I haven't a clue what that means or why it's erroring, can someone help with this please?

Thanks.
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Man it certainly aint easy getting your head around this object within an object milarky!

finally the penny dropped that $key was an object of type HTML::Form:TextInput !!!

So if I use the correct method against $key , I get results...
Code:
foreach my $key (@fields){
            print $key->type . "<br />";

Gives
hidden
hidden
hidden
text
text
password
hidden
this don't half give me a headache sometimes!


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
this might work as well:

Code:
foreach my $key (@fields){
        foreach my $kn( keys %{$key}){
            print $key->{$kn} . "<br>";
        }
}

the change is $key to [/b]%{$key}[/b] in the second foreach loop

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
That prints the entire web page, I thought
Code:
my @fields = $mech->find_all_inputs;
grabbed onlt the input fields?

Anyhow it seems the form doesn't generate dynamic field names.

I don't know any .NET ASP , but the form has some wierd hidden _fields one eing VIEWSTATE with a encrypted key like
wEPDwUKLTE4ODYyNDU4MQ9kFgJmD2QWBAIBD2QWBGYPFgIeBGhyZWYFFy9UaGVtZXMvU0xTL2Zhdmljb24uaWNvZAIBDxYCHwAFGy9UaGVtZXMvU0xTL2xheW91dF9kaXZzLmNzc2QCAw9kFggCAQ9kFgRmDw8WAh4EVGV4dAUfWW91IGFyZ

the form fields are like
ctl00$ContentPlaceHolder$Login1$UserName
and some how with the key the form names are dynamically renamed upon submit of the form.

Why does MS have to make things so complicated it's a simple 3 field form and a submit button!


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top