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;

In reply to Search SecondSpin.com by asiufy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.