Hi perlmonks,
I've got some code to work but I need an explanation of why it works.
I want to mechanize the login to a https://mysite.com.
Here is a snippet of my code.
my url = "https://mysite.com";
my $mech = WWW::Mechanize->new();
$mech->get($url);
$mech->follow_link(text => "Welcome", n => 1);
my $f = HTML::Form->parse(<<EOT, $url);
<form action="signin.jsp" onsubmit="returnblah();" method="post" id="s
+omethn_else">
<input type="text" name="username">user</input>
<input type="text" name="password">pass</input>
<input type="text" name="etc">etc</input>
</form>
EOT
# here is a workaround because of some javascript
$f->put_input("text", { name => "username" });
$f->value("username" => $username);
$f->put_input("text", { name => "password" });
$f->value("password" => $password);
$mech->submit();
Without the workaround my script doesn't work. But what I don't understand is how is it that $mech->submit() should include the changes I made with $f ??? How did they become associated? I didn't do, say, $mech->form($f->click->as_string); (which works by the way, with an error).
Thanks for any help,
Den.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.