WWW-Search

 view release on metacpan or  search on metacpan

Programs/WebSearch  view on Meta::CPAN

As the first line of output, print the approximate hit count.
As the last line of output, print the actual hit count.

=item --terse, -t

Do not print any URLs.
Only useful if you also specify --count.
If you specify --terse but not --count,
there will be no output no matter how many hits are found!

=item --all, -a

For each hit result, print all the URLs that the search engine
indicated were equivalent to it.  (Some URLs may refer to the same
object.)  Can be combined with --verbose; can not be combined with
--raw.

=item --raw, -r

For each hit result, print the raw HTML.
Not implemented for all backends.

=item --verbose, -v

Verbose mode.  Enumerate the returned URLs and show the description,
score, date, etc. for each.

=item --VERSION, -V

Print version information and exit immediately.

=item --debug <i>, -d <i>

Display back-end debugging information (with debug level <i>)

=item --host <hostname.sub.domain>

Set the _host option for the WWW::Search object (backend-dependent).

=item --port <i>

Set the _port option for the WWW::Search object (backend-dependent).

=item --username <bbunny>

Set the username with which to login to the backend.

=item --password <c4rr0t5>

Set the password with which to login to the backend.

=item --lwpdebug, -l

Display low-level libwww-perl debugging information

=back


=head1 ENVIRONMENT VARIABLES

The environment variable F<http_proxy> (or F<HTTP_PROXY>)
specifies a proxy, if any.


=head1 SEE ALSO

For the library, see L<WWW::Search>.

For a more sophisticated client, see L<AutoSearch>.


=head1 AUTHOR

C<WebSearch> was written by John Heidemann, <johnh@isi.edu>.
C<WebSearch> is maintained by Martin Thurn, <mthurn@cpan.org>.


=head1 COPYRIGHT

Copyright (c) 1996-1997 University of Southern California.
All rights reserved.

Redistribution and use in source and binary forms are permitted
provided that the above copyright notice and this paragraph are
duplicated in all such forms and that any documentation, advertising
materials, and other materials related to such distribution and use
acknowledge that the software was developed by the University of
Southern California, Information Sciences Institute.  The name of the
University may not be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.



=cut

use strict;

&usage('no arguments given') if ($#ARGV == -1);
# &usage if ($#ARGV >= 0 && $ARGV[0] eq '-?');

use Getopt::Long;
use WWW::Search;

use vars qw( $VERSION );
$VERSION = '2.14';

use vars qw( $sEngine $all $verbose $raw $iMax $print_version $debuglwp $debug );
use vars qw( @options $_host $_port $help $iShowCount $iGui $opt_list );
use vars qw( $opt_username $opt_password );
# Set default values:
$iShowCount = 0;
$iGui = 0;
my $iTerse = 0;
$_host = '';
$_port = '';
$sEngine = '';
undef $debug;

Programs/WebSearch  view on Meta::CPAN

  $, = "\n";
  print STDERR (sort @as), '';
  exit 0;
  } # list_engines

my $verbose_code;

sub print_result {
    my($result, $count) = @_;
    return if $iTerse;
    my($prefix) = "";
    if ($verbose) {
	my(@attribs) = ();
        $prefix = "$count. ";
	if (!defined($verbose_code)) {
	    $verbose_code = "";
	    foreach (qw(title description score normalized_score size change_date index_date)) {
	        $verbose_code .= "push(\@attribs, \"$_: \" . \$result->$_())\n" .
		    "\tif (defined(\$result->$_()));\n";
            };
	};
	eval $verbose_code;
        $prefix .= "(" . join(",\n\t", @attribs) . ")\n\t"
	    if ($#attribs >= 0);
    };

    if (defined($all)) {
        foreach ($result->urls()) {
            print "$prefix$_\n";
            $prefix = "\t";
        };
    } else {
	if (defined($raw)) {
	    print $result->raw(), "\n";
	} else {
	    print $prefix, $result->url, "\n";
	};
    };
}

sub print_error {
    my ($msg, $count) = @_;
    my $error = $verbose ? sprintf("[%3d] ", $count) : '';
    $error .= $msg;
    print STDERR $error, "\n" if $error ne '';
}

sub main {
    my $query = shift;
    my $count = 0;
    my $search = new WWW::Search($sEngine);
    $search->{_host} = $_host if $_host ne '';
    $search->{_port} = $_port if $_port ne '';
    my %hsOptions = ();

    if (0 < $debuglwp) {
	require LWP::Debug;
	LWP::Debug::level('+');
    }

    $search->http_proxy($ENV{'HTTP_PROXY'}) if ($ENV{'HTTP_PROXY'});
    $search->http_proxy($ENV{'http_proxy'}) if ($ENV{'http_proxy'});

    if (0 < scalar(@options))
      {
      foreach my $sPair (@options)
        {
        if ($sPair =~ m/^([^=]+)=(.*)$/)
          {
          my ($key, $value) = ($1, $2);
          # This is a bit of a hack.  A set of CGI options is not
          # strictly a hash, because multiple values for the same key
          # can be specified.  To get around this, we rely on the fact
          # that this hash of options is only used to construct a CGI
          # parameter list.  If we see multiple values for the same key,
          # we append the multiple values onto the value of the key in
          # CGI '?key=value' format.
          if (exists($hsOptions{$key}) && $hsOptions{$key} ne '')
            {
            # There was already an option of this key given; append
            # multiple values as CGI arguments:
            $hsOptions{$key} .= '&'.$key.'='.WWW::Search::escape_query($value);
            } # if exists
          else
            {
            # This is the only instance of this key; just insert the
            # hash value:
            $hsOptions{$key} = WWW::Search::escape_query($value);
            }
          } # if option is of the form key=value
        else
          {
          $hsOptions{$sPair} = '';
          }
        } # foreach $sPair
      } # if @options

    if (defined($iMax))
      {
      $search->maximum_to_retrieve($iMax);
      }
    else
      {
      $iMax = 10000;
      }

    $hsOptions{'search_debug'} = $debug if (defined($debug) and (0 < $debug));

    $iGui
    ? $search->gui_query(WWW::Search::escape_query($query), \%hsOptions)
    : $search->native_query(WWW::Search::escape_query($query), \%hsOptions);
    $search->login($opt_username, $opt_password);

    my($way) = 0; # 0=piecemeal, 1=all at once
    my($result);
    if (($iShowCount) && defined($search->approximate_result_count))
      {
      print "There are approximately " if $verbose;
      print $search->approximate_result_count;
      print " results." if $verbose;
      print "\n";



( run in 0.423 second using v1.01-cache-2.11-cpan-a1f116cd669 )