让机械化返回价值,甚至是错误信息的问题,唉!

时间:2011-03-31 11:31:34

标签: perl forms mechanize

我试图使用Perl模块Mechanize,但我遇到了一些麻烦。下面这段代码应该从google上传文件到fileserve,但它不起作用,它似乎没有返回任何错误,请帮忙!

use strict;
use warnings;
use WWW::Mechanize;

my $resp;

my $insert_url = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js';

use constant INDEX_SITE => 'fileserve.com';
use constant USERNAME => 'chuckaway';
use constant PASSWORD => 'chuckaway99';

my $mech = WWW::Mechanize->new();

my $url = 'http://www.fileserve.com/remote-upload.php';

$mech->get($url);

eval {
     #print "# submit login $url\n";
     $resp = $mech->submit_form(form_name => 'loginForm', 
                                fields => { username => 'loginUserName', 
                                password => 'loginUserPassword' }
                               );
     die $resp->status_line unless $resp->is_success;
     };

warn $@ if $@;
return  if $@;

$resp = $mech->get($url);

eval {
     $resp = $mech->submit_form(form_name => 'remoteUploadForm', fields => { urls => '$insert_url'});
     };

1 个答案:

答案 0 :(得分:0)

使用状态200提交带有密码的表单失败,它会再次返回登录表单。看看您的submit_form电话,您没有填写您之前在该计划中设置的凭据。

使用Wireshark或类似的网络嗅探器与已知良好的登录请求 - 响应对进行比较。

POST /login.php HTTP/1.1
TE: deflate,gzip;q=0.3
Connection: TE, close
Accept-Encoding: gzip
Host: www.fileserve.com
Referer: http://www.fileserve.com/remote-upload.php
User-Agent: WWW-Mechanize/1.66
Content-Length: 178
Content-Type: application/x-www-form-urlencoded
Cookie: PHPSESSID=2i8gu7jha1i98fjvemveebmvf0
Cookie2: $Version="1"

loginUserName=&loginUserPassword=&autoLogin=on&recaptcha_response_field=&recaptcha_challenge_field=&recaptcha_shortencode_field=&password=loginUserPassword&username=loginUserName

HTTP/1.1 200 OK
X-Powered-By: PHP/5.3.1
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Encoding: gzip
Vary: Accept-Encoding
Content-type: text/html
Connection: close
Transfer-Encoding: chunked
Date: Thu, 31 Mar 2011 13:29:14 GMT
Server: fileserve


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Free 1-Click File Hosting. Easy File Distribution, Fast and Secure. Share and upload files for free. Get unlimited online storage." />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>
                FileServe - Login - Free File Hosting, Online Storage &amp File Upload
        </title>
<link href="/styles/base.css?38" rel="stylesheet" type="text/css" />
<link rel="shortcut icon" href="/images/favicon.ico" />
<link rel="image_src" href="/images/fileserve_newsfeed.jpg" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="/script/fileserve.js"></script>




<script>
if (top != self) top.location = self.location;
</script>

<script>
/*$(document).ready(function(){
        $("body").append('<a href="javascript:displayOverlayDialog(\'bonus_promo\');" class="promo_tab"></a>');
});*/
$(document).ready(function() {
            DD_roundies.addRule('.panel, .panel .timing, .download_boxes .premium, #login_area, .comparison .plan, .file_control, .file_control .toolbar, .dialog, .tips_message, .comparison, .payout_table, .money_signup, .news_box, .my_earnings .payable, .dashboard .account .acc_table, .manager_alert, .premium_extend, .join_box, .dialog_choose_plan, ul.highlight', '6px', true);
            DD_roundies.addRule('.file_manager .file_control', '6px 6px 0 0', true);
            DD_roundies.addRule('.file_manager .file_control .toolbar', '6px 6px 0 0', true);
})
</script>
        <script src="/script/signup_validate.js" type="text/javascript"></script>
    <script type="text/javascript" src="/script/recaptcha_ajax.js"></script>
    <script src="/script/signin_captcha.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function(){


        });
        var reCAPTCHA_publickey='6LdSvrkSAAAAAOIwNj-IY-Q-p90hQrLinRIpZBPi';
    </script>
    <style>
    #captchaArea {margin: 5px auto; width:270px;}
    #captchaValue {width:80px;}
    #captchaErrLabel {display: block;}
    #captchaError {margin-bottom:4px; color:#FF3333;}
    #recaptcha_image {width:230px!important; height:57px!important;}
    #recaptcha_image img {width:230px!important; height:44px!important;}
    #recaptcha_btns {float:right; width:34px; padding-bottom:3px;}
    </style>

    </head>
    <body id="sign_up">
        <div id="container">








<script>

    $(document).ready(function(){
        $('#login').mouseenter(function(){
            $('#login_area').show();
        });
        $('#no_sign').click(function(){
            $("#login_area").hide();
        });

        $('#partner_payment_type2').change(onSelectChange);
        $('#partner_email2').keypress(onSelectChange);

        function onSelectChange(){
            var selected = $("#partner_payment_type2 option:selected");
            var regexp = selected.attr('rel');

            jQuery.validator.addMethod("patternCheck", function(value, element) {
                var re = new RegExp(regexp);
                return re.test(value);
            }, jQuery.format("Invalid payment account"));

            $('#promoForm #partner_email2').focus();
        }

        var promoFormValidator = $('#promoForm').validate({
            errorElement: 'span',
            errorClass: 'fail_info',
            errorPlacement: function(error, element){
                $('#promoError').html(error);
                //$(error).insertAfter(element.next());
            },
            success: function(label){
                label.remove();
            },
            rules: {
                partner_email2:{
                    required: true,
                    patternCheck: true
                }
            },
            messages: {
                partner_email2:{
                    required: "Provide your payment account",
                    patternCheck: "Invalid payment account"
                }
            }
        });

        $('#sys_clock .lang_select').bind('mouseenter mouseleave', function() {
            $('div:eq(0)', this).slideToggle(150);
            $(this).toggleClass('hover');
            num = $(this).hasClass('hover') ? $('a', this).size() : 1;
            $(this).stop(true, false).animate({ height: num * ($('a', this).height()+2) },200);
        });

    });
    function displayOverlayDialog(layerId) {
        window.scroll(0,0);
        //$('#upgrade_btn').attr('disabled', true);
        $('#middle_panel').fadeTo('slow', 0.5);
        $('.middle').fadeTo('slow', 0.5);
        $('#' + layerId).show();
    }

    function hideOverlayDialog(layerId) {
        $('#' + layerId).hide();
        //$('#upgrade_btn').attr('disabled', false);
        $('#middle_panel').fadeTo('slow', 1);
        $('.middle').fadeTo('slow', 1);
    }

    function changeLocale(locale) {
        $("#localeForm [name=locale]").val(locale);
        $("#localeForm").submit();
    };

    initClock('March 31, 2011 09:29:14', 'dynamic_clock');
</script>

<style>
input.bonuspromo {display:inline; padding:1px;}
</style>


    <!-- promo tab -->
    <a href="http://www.videobb.com/rewards.php?a=103" target="_blank" class="promo_tab promo_videobb">
        <!--[if IE 6]>
        <script>
        $(document).ready(function() {
            $(window).scroll(function() {
                $('.promo_tab').css('top', $(this).scrollTop() +192 + "px");
            });
        })
        </script>
        <![endif]-->
    </a>
    <!-- promo tab ends -->

<div id="header">
    <a href="/" id="logo" alt="Free File Hosting & File Upload with FileServe."><span>FileServe</span></a>
    <div class="sys_clock" id="sys_clock">
        <span id="dynamic_clock">09:29 AM, 31 March 2011 EST</span>
                <form id="localeForm" name="localeForm" action="/login.php" method="post"><input name="locale" type="hidden" value=""/></form>
    </div>
                <div id="menu">
            <div class="menu_tag off_left"></div>
<div id="menu_upload" class="menu_tag off_right_off"><a href="/upload-file.php">Upload</a></div>
<div id="menu_premium" class="menu_tag off_right_off"><a href="/premium.php">Premium</a></div>
<!--<div id="menu_money" class="menu_tag off_right_off"><a href="/partner-signup.php">Make Money</a></div>-->
<div id="menu_money" class="menu_tag off_right_off"><a href="/partner-info.php">Make Money</a></div>
<div id="menu_news" class="menu_tag off_right_off"><a href="/news.php">News</a></div>
<div id="menu_help" class="menu_tag off_right_hl"><a href="/help.php">Help</a></div>
<!-- <div id="menu_contact" class="menu_tag off_right_hl"><a href="/contact-us.php">Contact us</a></div> -->
<div id="menu_signup" class="menu_tag hl_right_end"><a href="/signup.php">Sign up</a></div>     </div>
        <div class="clear"></div>
        <div class="sub_bar">
            <div class="submenu">
                            </div>
            <span class="status"><strong>You are not logged in</strong> <a id="login" href="/login.php">Login</a> | <a href="/signup.php">Sign up</a></span>
            <form action="/login.php" method="POST">
            <div id="login_area" style="display:none">
                <table border="0" cellspacing="0" cellpadding="1">
                    <tr>
                        <td height="40" colspan="2"><h3>Login</h3></td>
                    </tr>

                    <tr>
                        <td>Username</td>
                        <td><label class="textfield"><input type="text" name="loginUserName" /></label></td>
                    </tr>
                    <tr>
                        <td>Password</td>
                        <td><label class="textfield"><input type="password" name="loginUserPassword" /></label></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <span class="caption"><input type="checkbox" name="autoLogin" checked> Remember me</span>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <table style="line-height:12px" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td>
                                        <div class="fpw_text"><a href="/forgot-password.php" class="forpw">Forgot password?</a></div>
                                    </td>
                                    <td rowspan="2" valign="top">
                                        <label class="btu_login"><input type="submit" name="loginFormSubmit" value="Login" /></label>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <div class="fpw_text"><a href="/retrieve_premium.php" class="forpw">Lost your premium account?</a></div>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>                </table>
                <a href="javascript:void(0)" id="no_sign" class="no_sign"></a>
            </div>
            </form>
        </div>

<div class="clear"></div>
</div>
<!---promo-->
<div id="bonus_promo" class="dialog_overlay" style="display:none;">
    <div class="dialog promo">
        <a class="close_btn" href="javascript:hideOverlayDialog('bonus_promo');"></a>

        <div class="panel">
        <form name="promoForm" id="promoForm" action="/partner-signup.php" method="post">
            <table>
                <tr>
                    <td colspan="3"><a class="banner" href="/partner-info.php"></a></td>
                </tr>
                            </table>
        </form>
        </div>

    </div>
</div>
<!---promo ends-->


            <div class="middle">
                <h1>Login</h1>
                <!--left-->
                <!--left end-->
                <!--right-->
                <div class="left_box login_box">
                    <div><form id="loginForm" name="loginForm" action="/login.php" method="post">
                        <table class="signup_tab">
                            <tr>
                                <td width="160" valign="top">Username</td>
                                <td width="272" class="textfield">
                                    <input type="text" size="38" maxlength="20" name="loginUserName" />
                                    <label>Enter your current username</label>
                                                                    </td>
                            </tr>
                            <tr>
                                <td width="160" valign="top">Password</td>
                                <td class="textfield">
                                    <input type="password" size="38" maxlength="20" name="loginUserPassword" />
                                    <label>Enter your current password</label>
                                                                    </td> 
                            </tr>
                            <tr>
                                <td></td>
                                <td><div><a href="/forgot-password.php" class="forpw">Forgot password?</a></div>
                        <div><a href="/retrieve_premium.php" class="forpw">Lost your premium account?</a></div>
                        </td>
                            </tr>
                            <tr>
                                <td></td>
                                <td><br/><span class="TandC"><input type="checkbox" name="autoLogin" checked> Remember me</span></td>
                            </tr>
                            <tr>
                        <td></td>
                        <td>
                        <div id="captchaArea" style="display:none;">
                                <div id="recaptcha_widget">
                                    <div id="recaptcha_btns">
                                        <div><a href="javascript:Recaptcha.reload()"><img width="25" height="17" id="recaptcha_reload" src="http://api.recaptcha.net/img/clean/refresh.gif" alt="Get a new challenge"/></a></div>
                                        <div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type('audio')"><img width="25" height="16" alt="Get an audio challenge" id="recaptcha_switch_audio" src="http://api.recaptcha.net/img/clean/audio.gif"></a></div>
                                        <div class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type('image')"><img width="25" height="16" alt="Get a visual challenge" id="recaptcha_switch_img" src="http://api.recaptcha.net/img/clean/text.gif"></a></div>
                                        <div><a href="javascript:Recaptcha.showhelp()"><img width="25" height="16" id="recaptcha_whatsthis" src="http://api.recaptcha.net/img/clean/help.gif" alt="Help"></a></div>
                                    </div>
                                    <div id="recaptcha_image"></div>
                                    <input type="text" id="recaptcha_response_field" class="textfield" size="30" name="recaptcha_response_field" />
                                    <input type="hidden" id="recaptcha_challenge_field" name="recaptcha_challenge_field" />
                                    <input type="hidden" id="recaptcha_shortencode_field" name="recaptcha_shortencode_field" value="" />

                                    <div id="captchaAreaLabel">
                                        <label class="recaptcha_only_if_image">Enter the code shown above</label>
                                        <label class="recaptcha_only_if_audio">Enter the numbers you hear</label>
                                    </div>
                                </div>
                            </div>
                            <div id="captchaError"></div>
                                    </td>
                    </tr>
                            <tr>
                                <td width="160">&nbsp;</td>
                        <td><br />
                                                <input class="btu4" type="submit" name="loginFormSubmit" value="Login" />
                                                </td>
                            </tr>                       </table>
                        </form>
                    </div>
                </div>  
                <!--right end-->    
                <div class="clear"></div>
            </div>
        <!--end middle-->
        <div class="tail"></div>
        </div>
        <!--footer-->

<div id="footer" class="footer">
    <div>
    <ul>
        <li class="title">Features</li>
        <li><a href="/upload-multiple-files.php">Upload Multiple Files</a></li>
        <li><a href="/remote-upload.php">Remote Upload</a></li>
        <li><a href="/ftp-upload.php">FTP Upload</a></li>
        <li><a href="/partner-info.php">Become an Affiliate</a></li>
        <li><a href="/link-checker.php">Check FileServe Links</a></li>
        <li><a href="/about-free-file-hosting.php">About Free File Hosting</a></li>
    </ul>
    <ul>
        <li class="title">Account</li>
        <li><a href="/login.php">Login</a></li>
        <li><a href="/signup.php">Signup for Free</a></li>
        <li><a href="/premium.php">Become a Premium User</a></li>
        <li><a href="/redeem.php">Redeem</a></li>
        <li><a href="/retrieve_premium.php">Reclaim Premium Account</a></li>
        <li><a href="http://reseller.fileserve.com">Become a Reseller</a></li>
    </ul>
    <ul>
        <li class="title">Support</li>
        <li><a href="/news.php">News</a></li>
        <li><a href="/faq.php">FAQ</a></li>
        <li><a href="/dmca.php">DMCA</a></li>
        <li><a href="/help.php">Help</a></li>
        <li><a href="/terms.php">Terms of Use</a></li>
        <li><a href="/sitemap.php">Site Map</a></li>
        <li><a href="/privacy-policy.php">Privacy Policy</a></li>
    </ul>
    <ul>
        <li class="title">Contact</li>
        <li><a href="/advertise-with-us.php">Advertise with us</a></li>
        <li><a href="/about-us.php">About us</a></li>
        <li><a href="/contact-us.php">Contact us</a></li>
        <li><a href="/link-to-us.php">Link to us</a></li>
    </ul>
    <div class="clear"></div>
    <p>Copyright &copy; 2010 FileServe, All Rights Reserved</p>
    <h3 class="footer_bottom">Free 1-Click File Hosting. Easy File Distribution, Fast and Secure. <br/>Get unlimited online storage.</h3>
    </div>
</div>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ?
"https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' (http://google-analytics.com/ga.js') type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-15255203-1");
pageTracker._trackPageview();
} catch(err) {}</script>

<script type="text/javascript"><!--
EXref="";top.document.referrer?EXref=top.document.referrer:EXref=document.referrer;//-->
</script><script type="text/javascript"><!--
EXs=screen;EXw=EXs.width;navigator.appName!="Netscape"?
EXb=EXs.colorDepth:EXb=EXs.pixelDepth;
navigator.javaEnabled()==1?EXjv="y":EXjv="n";
EXd=document;EXw?"":EXw="na";EXb?"":EXb="na";
location.protocol=="https:"?EXprot="https":EXprot="http";
EXref?EXref=EXref:EXref=EXd.referrer;EXsrc="src";
EXd.write("<img "+EXsrc+"="+EXprot+"://nht-2.extreme-dm.com",
"/n3.g?login=fsricky&amp;url="+escape(document.URL)+"&amp;pv=&amp;",
"jv="+EXjv+"&amp;j=y&amp;srw="+EXw+"&amp;srb="+EXb+"&amp;",
"l="+escape(EXref)+" height=1 width=1>");//-->
</script><noscript><div id="nneXTReMe"><img height="1" width="1" alt="" src="http://nht-2.extreme-dm.com/n3.g?login=fsricky&amp;url=nojs&amp;j=n&amp;jv=n&amp;pv=" /></div></noscript>
    </body>
</html>