This little script searches SecondSpin.com (used CD vendor) and mails you the results daily.

Comments, please !
#!/usr/bin/perl -w # # Just a quick hack to search SecondSpin.com for certain keywords, and + mail them # One more little thingie for your /etc/crontabs... # # Usage: perl ss.pl <string>\n"; # perl ss.pl -file <filename>\n"; # # The filename must contain an email address on the first line, and on +e keyword in each following line # use LWP::UserAgent; use Net::SMTP; use strict; my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/8.0"); my @searches; my $output; my $opts = shift; if ($opts eq "") { print "Usage: perl ss.pl <string>\n"; print " perl ss.pl -file <filename>\n"; exit; } if ($opts eq "-file") { my $filename = $ARGV[0]; open(FILE, $filename) or die "Can't open the file $filename!\n"; + while (<FILE>) { chomp; push @searches, $_; } } else { $searches[1] = $opts; } my $search_url = "http://www.secondspin.com/buy/search.cfm"; for (my $z=1; $z < scalar(@searches); $z++) { $searches[$z] =~ s/ /%20/g; my $req = HTTP::Request->new(POST => $search_url); $req->content_type('application/x-www-form-urlencoded'); my $content = "sp=1&nu=u&sr=1&er=100&sb=ar&st=" . $searches[$z]; $req->content($content); my $res = $ua->request($req); my @res = (split /\n/, $res->content); for (my $i=0;$i<scalar(@res);$i++) { if ($res[$i] =~ /artist\.cfm.+>(.+)<\/A>/i) { $output .= "$1\n"; } if ( $res[$i] =~ /<a href=\"\/buy.+>(.+)<\/a>/i) { $output .= "\t$1\n"; } if ( $res[$i] =~ /</ ) { # do nothing } else { if ($res[$i] =~ /^\t/) { $res[$i] =~ s/^\s+//; $res[$i] =~ s/\t//g; $output .= "\t" . $res[$i] . "\n"; } } } } print $output; my $subject = "Subject: SecondSpin results for " . scalar (localtime). + "\n"; my $smtp = Net::SMTP->new('mail.yourdomain.net', Hello => 'mail.yourdomain.net', Timeout => 30, Debug => 1,); $smtp->mail('admin@yourdomain.net'); $smtp->to($searches[0]); $smtp->data(); $smtp->datasend($subject); $smtp->datasend("\n"); $smtp->datasend($output); $smtp->dataend; $smtp->quit;

Replies are listed 'Best First'.
Re: Search SecondSpin.com
by YuckFoo (Abbot) on Feb 20, 2002 at 21:13 UTC
    I'll try it! This could be quite useful. One suggestion I have is that emailing results should be optional. Default should print results on STDOUT. I'll let you know how it goes, thanks.

    YuckFoo