I'm trying to write a script for myself that when provided with a list of users from youtube I want to request as friends will automatically send the request. I'm baffled why the submit piece from Mechanize doesn't seem to work as I expect. This is my code snippet to submit the form:
... $mech->follow_link( text => "Add as Friend"); my $page = $mech->content; my $hidden_id = $1 if $page =~ m/\<input type\=\"hidden\" name\=\" +friend_id\" value=\"(.*)\"\>/; my $friend_id = 'http://youtube.com/my_friends_invite_user?friend_ +id=' .$hidden_id; # print "FRIEND ID: $friend_id\n"; $mech->add_header( Referer => $friend_id ); $mech->form_number(3); my $form = $mech->form_number(3); $form->find_input('friend_id')->readonly(0); $mech->set_fields(friend_id => $hidden_id); $mech->field('group', 'Friends' ); $mech->click_button(name => 'action_invite');
Everything looks like it gets set properly but it never actually submits the form. I've also posted the source code behind the webpage if that helps below:
<form method="post" action="my_friends_invite_user"> <input type="hidden" name="friend_id" value="JMwzlfI6UQU"> <tr> <td class="formLabel">Username:</td> <td class="formField"><a href="/profile?user=wasteofaces">wasteo faces</a></td> </tr> <tr valign="top"> <td class="formLabel">Add As:</td> <td class="formField"> <select name="group"> <option value="">---</option> <option value="Family" >Family</option> <option value="Friends" SELECTED>Friends</option> </select> <div class="smallText">This person will be able to see the pri +vate videos you share with these groups in addition to your public vi +deos. </div> </td> </tr> <tr> <td class="formLabel">&nbsp;</td> <td class="formField"><input type="submit" name="action_invite" +value="Send Invite"></td> </tr> </form>
I'm obviously missing something so any and all suggestions are welcome.

In reply to YouTube and Mechanize form submission by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.