Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- #
- use warnings;
- use strict;
- use WWW::Mechanize::GZip;
- use feature 'say';
- use constant {
- true => 1,
- false =>0
- };
- my $mech = WWW::Mechanize::GZip->new();
- my @agents = (
- "Windows IE 6",
- "Windows Mozilla",
- "Mac Safari",
- "Mac Mozilla",
- "Linux Mozilla",
- "Linux Konqueror"
- );
- my $args = {};
- print "Url: ";
- chomp(my $url = <STDIN>);
- $url = "http://" . $url if (substr($url,0,7) ne "http://");
- my $i = 1;
- for (@agents)
- {
- say $i ." : " . $_;
- $i++;
- }
- while (true)
- {
- print "Elige un user agent: ";
- chomp(my $response = <STDIN>);
- if ($response !~ /\D/ and $response ne '')
- {
- if ($response <= scalar(@agents)) {
- $args->{agent} = $agents[$response-1];
- last;
- }
- else
- {
- say "User agent no disponible";
- }
- }
- else
- {
- say "NUeros por favor";
- }
- }
- $mech->agent_alias($args->{agent});
- $mech->get($url) || die $!;
- say (('*' x 30) . " Informacion " . ('*' x 30));
- print $_->dump for $mech->forms();
- {
- require LWP::UserAgent;
- my $ua = LWP::UserAgent->new;
- $ua->timeout(10);
- $ua->env_proxy;
- my $response = $ua->get($url);
- if ($response->is_success) {
- my @forms = parse($response->decoded_content);
- if (@forms) {
- foreach (@forms)
- {
- say (('*' x 80));
- say $_;
- }
- }
- }
- else {
- die $response->status_line;
- }
- }
- acces_forms();
- my $result = $args->{response}->content();
- say $result;
- open(FILE, "> page.html") or die $!;
- print FILE $result ;
- close FILE;
- sub acces_forms
- {
- say "Submit for request";
- print "Form id : ";
- chomp($args->{form_id} = <STDIN>);
- my $fields = {};
- while (true)
- {
- print "Field : ";
- chomp(my $field = <STDIN>);
- last if($field eq "Submit");
- print "Value : ";
- chomp(my $value = <STDIN>);
- $fields->{$field} = $value;
- }
- $args->{response} = $mech->submit_form(
- form_id => $args->{form_id},
- #form_number=> 1,
- fields => $fields
- );
- }
- sub parse
- {
- my $html = shift;
- my @forms = ();
- while ($html =~ m{\<form(.*?)\>}g)
- {
- push (@forms,$1);
- }
- while ($html =~ m{\<input(.*?)\>}g)
- {
- push (@forms,$1);
- }
- if (@forms) {
- return @forms;
- }
- else
- {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement