#!/usr/bin/perl ########################################### # formfields -- extract form field names # from a HTML page containing forms # Mike Schilli, 2002 (m@perlmeister.com) ########################################### use warnings; use strict; use LWP::Simple; use HTML::Form; use Pod::Usage; use Getopt::Std; use File::Basename; our $CVSVERSION = '$Revision: 1.4 $'; our ($VERSION) = ($CVSVERSION =~ /(\d+\.\d+)/); getopts( 'ivh', \ my %opts ) or pod2usage(); # Print out the version and exit if desired die basename($0), " v$VERSION\n" if exists $opts{v}; # Print out help if desired pod2usage(-verbose => 2) if $opts{h}; my $HTML; my %seen = (); if(@ARGV) { for(@ARGV) { if(m#://#) { $HTML .= get($_) or die "Getting url '$_' failed"; } else { open FILE, "<$_" or die "Cannot open '$_'"; $HTML .= join '', ; close FILE; } } } else { $HTML = join '', <>; } # Silly HTML::Form insists on a base url my $form = HTML::Form->parse($HTML, "http://blah.com"); my $indent = ""; $indent = " " if exists $opts{i}; for my $f ($form->inputs()) { my $name = ""; $name = $f->name() if defined $f->name(); next if $seen{$name}++; print "$indent$name\n"; } __END__ =head1 NAME formfields - extract form field names from a HTML page =head1 DOWNLOAD _SRC_HERE_ =head1 SYNOPSIS formfields [-hvi] [file|url] ... Options: -h print help and exit -v print version and exit -i indent the output by 4 spaces per line =head1 DESCRIPTION B parses an HTML page and prints out the names of all HTML FORM fields it finds. It takes either file name(s) or URL(s) as input. =head1 EXAMPLES $ formfields http://www.amazon.com index field-keywords Go =head1 LEGALESE Copyright 2002 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR 2002, Mike Schilli