A Multisearch Results Tool
A logical way to extend the
search_rank.plx
script is to make it output its
results in the form of web pages, and to let one specify multiple
search engines and multiple query strings. The script in Example 18-2 (called search_rank2.plx
)
does just that.
Example 18-2. A script to submit multiple queries to multiple search engines
#!/usr/bin/perl -w # search_rank2.plx # more full-featured search-ranking script: multiple engines, # multiple search queries, Web-based output. use strict; use WWW::Search; # configuration: my $max_results = 50; my $base_url = 'http://www.devicelink.com/'; my @engines = qw(AltaVista Google Lycos); my $result_fs_path = '/w1/e/elanus/search_rank'; my $result_web_path = '/search_rank'; my $index_file = "$result_fs_path/index.html"; my %data; # HoH: primary key: engine name. secondary key: query string. # value: rank # see end of script, after the __END_ _ token, for list of search queries my $url_pattern = quotemeta($base_url); chomp(my @queries = <DATA>); foreach my $engine (@engines) { my $engine_dir = $result_fs_path . '/' . $engine; unless (-e $engine_dir) { mkdir $engine_dir or die "can't mkdir '$engine_dir': $!"; } my $search = new WWW::Search($engine); $search->maximum_to_retrieve($max_results); foreach my $query (@queries) { my $query_dir = clean_name($query); my $result_dir = $engine_dir . '/' . $query_dir; unless (-e $result_dir) { mkdir $result_dir or die "can't mkdir '$result_dir': $!"; } my $detail_file = "$result_fs_path/$engine/$query_dir/index.html"; ...
Get Perl for Web Site Management now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.