Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5. use WWW::Mechanize;
  6. use HTTP::Cookies;
  7.  
  8. my $url = "http://sampleurl.com";
  9. my $dir = 'C:\pl';
  10. my $mech = WWW::Mechanize->new();
  11. $mech->cookie_jar(HTTP::Cookies->new());
  12. $mech ->credentials("sampleurl.com:80", "sampleurl.com", "username", "password");
  13. $mech->get($url);
  14. my $res = $mech->res();
  15. if($res->is_success){
  16. my $filename = $res->filename();
  17. print $filename;
  18. $mech->save_content( $dir.'\'.$filename, binmode => ':raw', decoded_by_headers => 1 );
  19. print $mech->status;
  20. }else{
  21. print "Error";
  22.  
  23. }
  24.  
  25. exit 0;
  26.  
  27. use MIME::Types qw(by_mediatype);
  28.  
  29. my $filename = $r->filename();
  30. if(!$filename) { $filename = 'untitled'; }
  31.  
  32. if($filename !~ /.[a-zA-Z0-9]{1,4}$/) {
  33. my $type = $res->header('Content-Type');
  34. my $ext = 'txt';
  35.  
  36. if($type) {
  37. my @types = by_mediatype($type);
  38.  
  39. if($#types > -1) {
  40. $ext = $types[0][0];
  41. }
  42. }
  43.  
  44. $filename .= '.' . $ext;
  45. }
  46.  
  47. print $filename;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement