in reply to Is there a better way to do this? I need to keep track of results...
That would look something like this (untested):
#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; use HTML::TokeParser; use MIME::Lite; use Fcntl; use SDBM_File; tie my %url_seen, 'SDBM_File', 'urls.dbm', O_RDWR|O_CREAT, 0666); while (1) { my $msg; my @search = ("broken hdtv","fix hdtv","does not work hdtv"); my $connection = WWW::Mechanize->new(); foreach my $term (@search) { $connection->get("http://portland.craigslist.org/"); $connection->form_number(1); $connection->field("query",$term); $connection->click(); my @link = $connection->find_all_links(url_regex => qr/(ele|zip +)\/[0-9]+/i); foreach my $link (@link) { my $tempLink=$link->url_abs; chomp $tempLink; if (not $url_seen{$tempLink}) { $url_seen{$tempLink} = 1; $msg = MIME::Lite->new( To =>'xxxxxxxxxx@vtext.com', Subject =>'CL Link', Type =>'text/plain; charset="iso-8859-1"', Data =>"There is a new link on craigslist." ); close OUTFILE; } } } if ( $msg ) { $msg->send; } sleep(300); }
|
|---|