Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Script doesn't return any error,but torrent isn't uploaded.

by cesapun (Acolyte)
on Sep 09, 2011 at 16:53 UTC ( #925129=perlquestion: print w/ replies, xml ) Need Help??
cesapun has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to write a perl script that upload torrent to a site.Script doesn't return any error,but torrent isn't uploaded.

Please,what i'm doing wrong?

#!/usr/bin/perl use strict; use warnings; my $username = "test"; my $password = "lol"; use WWW::Mechanize; my $name = $ARGV[0]; #%N - Title of torrent my $descr= "none"; foreach(glob "*.torrent"){ use_contents($_); } sub use_contents{ my $filename = shift; my $torrent_file = $filename; my $mech = WWW::Mechanize->new( autocheck => 1); #Initializes WWW::Mec +hanize $mech->get("http://localhost/TB_ALPHA/login.php"); #Retrieves The Logi +n Page print "Logging Into ES, Please Wait.\n"; #Alerts The User $mech->submit_form( #Logs Us Into BTN form_number => 0, fields => { username => "$username", password => "$password", } ); $mech->get("http://localhost/TB_ALPHA/upload.php"); sleep 2; warn "wait"; $mech->field('file', $torrent_file); #input torrent file warn "wait $torrent_file"; $mech->field('name', $name); #file name warn "wait $name"; $mech->field('descr', $descr); #description warn "wait $descr"; $mech->value(3); #category warn "wait"; $mech->click_button(value => "Do it!"); #Clicks do it warn "wait"; }

Thanks in advance

Comment on Script doesn't return any error,but torrent isn't uploaded.
Download Code
Re: Semi-up script doesn't work
by blue_cowdawg (Prior) on Sep 09, 2011 at 17:04 UTC
        Script doesn't return any error,but torrent isn't uploaded.

    I haven't used WWW::Mechanize much but the first thing that leaps out at me is you are not doing any sort of error detection within the script. There are a couple of methods I'd suggest you read up on for the module the first being  success() and the other being status()

      $mech->get("http://localhost/TB_ALPHA/upload.php"); sleep 2; warn "wait"; $mech->field('file', $torrent_file); #input torrent file warn "wait $torrent_file"; $mech->field('name', $name); #file name warn "wait $name"; $mech->field('descr', $descr); #description warn "wait $descr"; $mech->value(3); #category warn "wait"; $mech->click_button(value => "Do it!"); #Clicks do it warn "wait";

    That bit there makes me suspicious as well. I don't think it is doing what you think it is...


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: Semi-up script doesn't work
by cesapun (Acolyte) on Sep 09, 2011 at 17:11 UTC
    well,if it doesn't doing what i want,how can i input file,write torr name and others? many thanks in advance
Re: Script doesn't return any error,but torrent isn't uploaded.
by Corion (Pope) on Sep 09, 2011 at 17:12 UTC

    Also, print $mech->content to see the "current page". Maybe wherever you're trying to upload to uses Javascript or something else. If all else fails, compare the data your browser sends to the target website against what your script sends.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://925129]
Approved by blue_cowdawg
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-07-28 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (209 votes), past polls