|
Posted by Paul Bell on March 21, 2005, 3:24 pm
Please log in for more thread options
Hello
I am completely new to Perl and am needing some help with a short script I
am using to search ebay for new items.
The script parses a HTML page generated from an ebay search and looks for
all the auction links and emails the list to me.
The script works wonderfully, but if I put in a strong criteria to reduce my
search results, ebay usually brings back a list of other auctions it thinks
I will be interested in ie from other categories/countries/etc.
What I really need to do is only email the links that are above the phrase
"Some of the matching items found in other eBay areas" in the HTML.
#!/usr/bin/perl
# This is a replacement to Hack17
# The original relied on the WWW::Search::EBay Module
# Which has been redeveloped to support only Linux/UNIX's !!
# This code make no use of it and relies on common modules
# it also emails in a windows environment
# doesn't makes use of sendmail (doen't exist on windows, unless its 3rd
party)
# You will Probably need to install MIME::Lite and possibly Net::SMTP
# Auhtor Keith Howlette
# www.keith-howlette.com
# Use it as you please any bugs to "khowlette<at>bigfoot.com"
#################################################################
# Hacking th hack
# search for more than one item.
# The search items could be load from a file
# and used to feed main body of program.
#
# I may set this up on a website and allow poeple to submit searches
# need a good fee linux host that allows perl script to run.
###################################################################
use strict;
use LWP 5.64;
use URI;
use HTML::LinkExtor;
use HTML::HeadParser;
use Net::SMTP;
use MIME::Lite;
# Set too your country e.g. ebaycom.au
my $country=".co.uk";
my $base="http://search.ebay".$country."/ws/search/SaleSearch";
# Title to search for
my $title="radeon 9700*";
# Catergory to search get from http://listings.ebay.co.uk my $cat ="160";
#your email address
my $email = qw /me@me.com/;
#your mail server
my $mailsrv =qw /smtp@me.com/;
# File to keep items number already seen
my $localfile="listing.txt";
# declare some vars
my ($a,$b,$line, $itemnumber,@title,$results,%data,%olditems,$key);
#Set hash to nothing
%data=();
my $browser = LWP::UserAgent->new;
# Un comment if you need to use a proxy - replace with real address and port
#$browser->proxy(['http', 'ftp'], 'http://10.111.10.11:8080/');
my $url =URI->new($base);
$url->query_form(
'sacat'=> $cat,
'sasaleclass'=> '2',
'satitle'=> $title
);
# set up the link handler sub
my $link_extor = HTML::LinkExtor->new(&handle_links);
#get search results
my $response = $browser->get($url);
#get the links
$link_extor->parse($response->content);
#get items already seen in hash %olditems
my %olditems=();
if (-s $localfile)
{
open (INFILE,"$localfile");
while (<INFILE> )
{
chomp;
next if $_ eq "";
$olditems=1;
}
close (INFILE);
}
# delete items from %data hash already seen
foreach $key (keys %olditems)
{
if (exists($data))
{
delete $data;
}
}
# *** save any remaining new entries to file ***
open (OUTFILE,">>$localfile");
my $mailbody="";
foreach $itemnumber (keys %data)
{
my $line=&get_title($data);
print OUTFILE $itemnumber."n";
#print "Line=".$line."n";
$mailbody=$mailbody.$line;
}
close (OUTFILE);
#send mail
my $msg = MIME::Lite->new
(
To => $email,
From => $email,
Subject =>"Ebay Search for [".$title."]",
Type =>'multipart/related'
);
$msg->attach(Type => 'text/html', Data => qq{ $mailbody }
);
MIME::Lite->send('smtp', $mailsrv, Timeout=>60);
$msg->send if $mailbody ne "";
######################################
sub handle_links
{
my ($tag, %links)=@_;
my $key;
if ($tag eq 'a')
{
foreach $key (keys %links)
{
#search for links with Viewitem
if ($key eq 'href')
{
if ( $links =~ m/ViewItem/)
{
#get the item number from the link
$links =~ m/item=(d+)/;
$data=$links;
}
}
}
}
}
sub get_title($)
{
my ($page)=@_;
my $itempage = LWP::UserAgent->new;
my $item_contents=$itempage->get($page);
my $p = HTML::HeadParser->new;
$p->parse($item_contents->content);
my $link="<p><a href="$page">".$p->header('Title')."</p>";
return $link;
}
If anyone could edit the code I would be extremely grateful.
Paul
|
|
Posted by Brian McCauley on March 21, 2005, 4:34 pm
Please log in for more thread options
Paul Bell wrote:
> Hello
>
> I am completely new to Perl and am needing some help with a short script I
> am using to search ebay for new items.
OK I'll give you general advice.
> The script parses a HTML page generated from an ebay search and looks for
> all the auction links and emails the list to me.
>
> The script works wonderfully, but if I put in a strong criteria to reduce my
> search results, ebay usually brings back a list of other auctions it thinks
> I will be interested in ie from other categories/countries/etc.
>
> What I really need to do is only email the links that are above the phrase
> "Some of the matching items found in other eBay areas" in the HTML.
In that case, rather than using HTML::LinkExtor simply use HTML::Parser
directly so that you can devine a callback for text too. To see how to
achive the functionality of HTML::LinkExtor using HTML::Parser see the
source of HTML::LinkExtor since that's how it works.
Your text callback can then sent a flag to tell the link callback to
stop recoding.
>
>
> #!/usr/bin/perl
> # This is a replacement to Hack17
> # The original relied on the WWW::Search::EBay Module
> # Which has been redeveloped to support only Linux/UNIX's !!
> # This code make no use of it and relies on common modules
> # it also emails in a windows environment
> # doesn't makes use of sendmail (doen't exist on windows, unless its 3rd
> party)
> # You will Probably need to install MIME::Lite and possibly Net::SMTP
> # Auhtor Keith Howlette
> # www.keith-howlette.com
> # Use it as you please any bugs to "khowlette<at>bigfoot.com"
> #################################################################
> # Hacking th hack
> # search for more than one item.
> # The search items could be load from a file
> # and used to feed main body of program.
> #
> # I may set this up on a website and allow poeple to submit searches
> # need a good fee linux host that allows perl script to run.
>
> ###################################################################
>
>
> use strict;
Good start but use warnings would probably be a wise move too.
> use LWP 5.64;
> use URI;
> use HTML::LinkExtor;
> use HTML::HeadParser;
> use Net::SMTP;
> use MIME::Lite;
>
> # Set too your country e.g. ebaycom.au
> my $country=".co.uk";
>
> my $base="http://search.ebay".$country."/ws/search/SaleSearch";
If you use double quotes you don't need explicit concat.
my $base="http://search.ebay$country/ws/search/SaleSearch";
>
> # Title to search for
> my $title="radeon 9700*";
>
> # Catergory to search get from http://listings.ebay.co.uk > my $cat ="160";
>
> #your email address
> my $email = qw /me@me.com/;
Using q rather than qw would be more ideomatic for a scalar.
>
> #your mail server
> my $mailsrv =qw /smtp@me.com/;
>
>
> # File to keep items number already seen
> my $localfile="listing.txt";
>
> # declare some vars
> my ($a,$b,$line, $itemnumber,@title,$results,%data,%olditems,$key);
You are suffering from premature declaration. Try to get into the habit
of declaring all varialbles in the smallest applicable lexical scope
(i.e. as late as possible).
The package variables $a and $b are special. It is therefore generally
advised to aviod using those names for lexical variables.
>
> #Set hash to nothing
> %data=();
This is redundant, newly created hashes start out empty.
> my $browser = LWP::UserAgent->new;
> # Un comment if you need to use a proxy - replace with real address and port
> #$browser->proxy(['http', 'ftp'], 'http://10.111.10.11:8080/');
> my $url =URI->new($base);
>
> $url->query_form(
> 'sacat'=> $cat,
> 'sasaleclass'=> '2',
> 'satitle'=> $title
> );
>
> # set up the link handler sub
> my $link_extor = HTML::LinkExtor->new(&handle_links);
my $link_extor = HTML::Parser->new(
start_h => [&handle_links, "tagname,attr"],
report_tags => [ 'a' ],
text_h => [ &handle_text, "dtext" [,
);
> #get search results
> my $response = $browser->get($url);
>
> #get the links
> $link_extor->parse($response->content);
>
> #get items already seen in hash %olditems
> my %olditems=();
> if (-s $localfile)
> {
>
> open (INFILE,"$localfile");
You should always check that open()ing a file succeded. At the very
least put "or die $!". Ideally put something more.
The legacy 2-arg form of open() should generally be avoided.
open (INFILE,'<',$localfile) or die $!;
> while (<INFILE> )
> {
> chomp;
> next if $_ eq "";
> $olditems=1;
> }
> close (INFILE);
> }
>
> # delete items from %data hash already seen
> foreach $key (keys %olditems)
You should generally put my in front of the for interator variable.
foreach my $key (keys %olditems)
Actually Perl will assume the my. IMNSHO it should emit a warning when
it does so.
> {
> if (exists($data))
> {
> delete $data;
> }
The effort of testing exists is not justified. Just delete unconditionally.
Also note you can delete multiple elements of a hash at once.
delete @data{keys %olditems};
> }
>
>
> # *** save any remaining new entries to file ***
> open (OUTFILE,">>$localfile");
You should always check that open()ing a file succeded. At the very
least put "or die $!".
> my $mailbody="";
>
> foreach $itemnumber (keys %data)
> {
> my $line=&get_title($data);
Why are you using the speacial &-prefixed call syntax? Do you know what
it's special semantics are? Do you need them?
> print OUTFILE $itemnumber."n";
> #print "Line=".$line."n";
> $mailbody=$mailbody.$line;
Perl has a .= operator to append to a string.
$mailbody.=$line;
> }
> close (OUTFILE);
>
> #send mail
> my $msg = MIME::Lite->new
> (
> To => $email,
> From => $email,
> Subject =>"Ebay Search for [".$title."]",
> Type =>'multipart/related'
> );
>
> $msg->attach(Type => 'text/html', Data => qq{ $mailbody }
> );
>
> MIME::Lite->send('smtp', $mailsrv, Timeout=>60);
>
> $msg->send if $mailbody ne "";
>
>
> ######################################
> sub handle_links
> {
>
> my ($tag, %links)=@_;
> my $key;
You are suffering from preature declaration again.
> if ($tag eq 'a')
> {
> foreach $key (keys %links)
> {
> #search for links with Viewitem
> if ($key eq 'href')
Why are you looping if you only want one element of the hash?
> {
> if ( $links =~ m/ViewItem/)
> {
> #get the item number from the link
> $links =~ m/item=(d+)/;
>
> $data=$links;
You should never use $1 without checking the match succeded.
my $href = $links;
$data= $href if $href && $href =~ /ViewItem.*item=(d+)/;
Or since you are now calling this callback directly from HTML::Parser
not HTML::LinkExtor you'd need to make the link absolute yourself.
$data= URI->new($href, $base)->abs($base)
if $href && $href =~ /ViewItem.*item=(d+)/;
> sub get_title($)
Why are you defining this with a prototype. There's no need. It is too
late. And you told Perl to ignore it anyhow.
You'll also need something like:
sub handle_text {
$seen_marker++ if shift =~ /Some of the matching items found in
other eBay areas/;
}
Declaring $seen_marker and checking it in handle_links is left as an
exercise for the reader.
|
|
Posted by Paul Bell on March 21, 2005, 5:06 pm
Please log in for more thread options
Hello
Thanks for this very informative edit and speedy response.
I hope you wont be offend by saying that I know nothing of Perl and I
grabbed this script from www.keith-howlette.com - I was going to put a note
saying this wasnt my code.
I am a computer scientist and should really spend the time to learn this
language, but I was just playing around with an automated ebay search, and
have been struggling to find a solution rather than create my own from
scratch with my existing knowledge. There are no apps/websites that offer
the power of this simple script, but I was hit by a problem which I knew
very little of how to fix.
I will have a look at what you suggest, but I think it will be an uphill
task. If it is reasonably simple to stop the parser after the phrase I would
be very grateful if someone could post a solution.
Thanks,
Paul
>
>
> Paul Bell wrote:
>> Hello
>>
>> I am completely new to Perl and am needing some help with a short script
>> I am using to search ebay for new items.
>
> OK I'll give you general advice.
>> The script parses a HTML page generated from an ebay search and looks for
>> all the auction links and emails the list to me.
>>
>> The script works wonderfully, but if I put in a strong criteria to reduce
>> my search results, ebay usually brings back a list of other auctions it
>> thinks I will be interested in ie from other categories/countries/etc.
>>
>> What I really need to do is only email the links that are above the
>> phrase "Some of the matching items found in other eBay areas" in the
>> HTML.
>
> In that case, rather than using HTML::LinkExtor simply use HTML::Parser
> directly so that you can devine a callback for text too. To see how to
> achive the functionality of HTML::LinkExtor using HTML::Parser see the
> source of HTML::LinkExtor since that's how it works.
>
> Your text callback can then sent a flag to tell the link callback to stop
> recoding.
>
>>
>>
>> #!/usr/bin/perl
>> # This is a replacement to Hack17
>> # The original relied on the WWW::Search::EBay Module
>> # Which has been redeveloped to support only Linux/UNIX's !!
>> # This code make no use of it and relies on common modules
>> # it also emails in a windows environment
>> # doesn't makes use of sendmail (doen't exist on windows, unless its 3rd
>> party)
>> # You will Probably need to install MIME::Lite and possibly Net::SMTP
>> # Auhtor Keith Howlette
>> # www.keith-howlette.com
>> # Use it as you please any bugs to "khowlette<at>bigfoot.com"
>> #################################################################
>> # Hacking th hack
>> # search for more than one item.
>> # The search items could be load from a file
>> # and used to feed main body of program.
>> #
>> # I may set this up on a website and allow poeple to submit searches
>> # need a good fee linux host that allows perl script to run.
>>
>> ###################################################################
>>
>>
>> use strict;
>
> Good start but use warnings would probably be a wise move too.
>
>> use LWP 5.64;
>> use URI;
>> use HTML::LinkExtor;
>> use HTML::HeadParser;
>> use Net::SMTP;
>> use MIME::Lite;
>>
>> # Set too your country e.g. ebaycom.au
>> my $country=".co.uk";
>>
>> my $base="http://search.ebay".$country."/ws/search/SaleSearch";
>
> If you use double quotes you don't need explicit concat.
>
> my $base="http://search.ebay$country/ws/search/SaleSearch";
>
>
>>
>> # Title to search for
>> my $title="radeon 9700*";
>>
>> # Catergory to search get from http://listings.ebay.co.uk >> my $cat ="160";
>>
>> #your email address
>> my $email = qw /me@me.com/;
>
> Using q rather than qw would be more ideomatic for a scalar.
>>
>> #your mail server
>> my $mailsrv =qw /smtp@me.com/;
>>
>>
>> # File to keep items number already seen
>> my $localfile="listing.txt";
>>
>> # declare some vars
>> my ($a,$b,$line, $itemnumber,@title,$results,%data,%olditems,$key);
>
> You are suffering from premature declaration. Try to get into the habit of
> declaring all varialbles in the smallest applicable lexical scope (i.e. as
> late as possible).
>
> The package variables $a and $b are special. It is therefore generally
> advised to aviod using those names for lexical variables.
>
>>
>> #Set hash to nothing
>> %data=();
>
> This is redundant, newly created hashes start out empty.
>
>> my $browser = LWP::UserAgent->new;
>> # Un comment if you need to use a proxy - replace with real address and
>> port
>> #$browser->proxy(['http', 'ftp'], 'http://10.111.10.11:8080/');
>> my $url =URI->new($base);
>>
>> $url->query_form(
>> 'sacat'=> $cat,
>> 'sasaleclass'=> '2',
>> 'satitle'=> $title
>> );
>>
>> # set up the link handler sub
>> my $link_extor = HTML::LinkExtor->new(&handle_links);
>
> my $link_extor = HTML::Parser->new(
> start_h => [&handle_links, "tagname,attr"],
> report_tags => [ 'a' ],
> text_h => [ &handle_text, "dtext" [,
> );
>
>
>> #get search results
>> my $response = $browser->get($url);
>>
>> #get the links
>> $link_extor->parse($response->content);
>>
>> #get items already seen in hash %olditems
>> my %olditems=();
>> if (-s $localfile)
>> {
>>
>> open (INFILE,"$localfile");
>
> You should always check that open()ing a file succeded. At the very least
> put "or die $!". Ideally put something more.
>
> The legacy 2-arg form of open() should generally be avoided.
>
> open (INFILE,'<',$localfile) or die $!;
>
>
>> while (<INFILE> )
>> {
>> chomp;
>> next if $_ eq "";
>> $olditems=1;
>> }
>> close (INFILE);
>> }
>>
>> # delete items from %data hash already seen
>> foreach $key (keys %olditems)
>
> You should generally put my in front of the for interator variable.
>
> foreach my $key (keys %olditems)
>
> Actually Perl will assume the my. IMNSHO it should emit a warning when it
> does so.
>
>> {
>> if (exists($data))
>> {
>> delete $data;
>> }
>
> The effort of testing exists is not justified. Just delete
> unconditionally.
>
> Also note you can delete multiple elements of a hash at once.
>
> delete @data{keys %olditems};
>
>> }
>>
>>
>> # *** save any remaining new entries to file ***
>> open (OUTFILE,">>$localfile");
>
> You should always check that open()ing a file succeded. At the very least
> put "or die $!".
>
>> my $mailbody="";
>>
>> foreach $itemnumber (keys %data)
>> {
>> my $line=&get_title($data);
>
> Why are you using the speacial &-prefixed call syntax? Do you know what
> it's special semantics are? Do you need them?
>
>> print OUTFILE $itemnumber."n";
>> #print "Line=".$line."n";
>> $mailbody=$mailbody.$line;
>
> Perl has a .= operator to append to a string.
>
> $mailbody.=$line;
>
>> }
>> close (OUTFILE);
>>
>> #send mail
>> my $msg = MIME::Lite->new
>> (
>> To => $email,
>> From => $email,
>> Subject =>"Ebay Search for [".$title."]",
>> Type =>'multipart/related'
>> );
>>
>> $msg->attach(Type => 'text/html', Data => qq{ $mailbody }
>> );
>>
>> MIME::Lite->send('smtp', $mailsrv, Timeout=>60);
>>
>> $msg->send if $mailbody ne "";
>>
>>
>> ######################################
>> sub handle_links
>> {
>>
>> my ($tag, %links)=@_;
>> my $key;
>
> You are suffering from preature declaration again.
>
>> if ($tag eq 'a')
>> {
>> foreach $key (keys %links)
>> {
>> #search for links with Viewitem
>> if ($key eq 'href')
>
> Why are you looping if you only want one element of the hash?
>
>> {
>> if ( $links =~ m/ViewItem/)
>> {
>> #get the item number from the link
>> $links =~ m/item=(d+)/;
>>
>> $data=$links;
>
> You should never use $1 without checking the match succeded.
>
> my $href = $links;
> $data= $href if $href && $href =~ /ViewItem.*item=(d+)/;
>
> Or since you are now calling this callback directly from HTML::Parser not
> HTML::LinkExtor you'd need to make the link absolute yourself.
>
> $data= URI->new($href, $base)->abs($base)
> if $href && $href =~ /ViewItem.*item=(d+)/;
>
>> sub get_title($)
>
> Why are you defining this with a prototype. There's no need. It is too
> late. And you told Perl to ignore it anyhow.
>
> You'll also need something like:
>
> sub handle_text {
> $seen_marker++ if shift =~ /Some of the matching items found in other
> eBay areas/;
> }
>
> Declaring $seen_marker and checking it in handle_links is left as an
> exercise for the reader.
>
|
|
Posted by John Bokma on March 21, 2005, 6:51 pm
Please log in for more thread options
Paul Bell wrote:
>
> Hello
>
> I am completely new to Perl and am needing some help with a short
> script I am using to search ebay for new items.
>
> The script parses a HTML page generated from an ebay search and looks
> for all the auction links and emails the list to me.
>
> The script works wonderfully, but if I put in a strong criteria to
> reduce my search results, ebay usually brings back a list of other
> auctions it thinks I will be interested in ie from other
> categories/countries/etc.
>
> What I really need to do is only email the links that are above the
> phrase "Some of the matching items found in other eBay areas" in the
> HTML.
If this can be "recognised" by differences in mark up easily (or the use of
class or id attribute) I would say give HTML::TreeBuilder a try,
see http://johnbokma.com/perl/froogle-script.html
for an example.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
|
|
Posted by Keith Howlette on April 18, 2005, 7:29 am
Please log in for more thread options
Hi
I've posted a new version of the code on my website
http://www.keith-howlette.com/download/hack17v101.pl I've reviewed
the code and it now separates out the items and disregards Ebay's
recommended. Give it a try and email me if there are other problems
Keith Howlette
> Hello
>
> I am completely new to Perl and am needing some help with a short script I
> am using to search ebay for new items.
>
> The script parses a HTML page generated from an ebay search and looks for
> all the auction links and emails the list to me.
>
> The script works wonderfully, but if I put in a strong criteria to reduce my
> search results, ebay usually brings back a list of other auctions it thinks
> I will be interested in ie from other categories/countries/etc.
>
> What I really need to do is only email the links that are above the phrase
> "Some of the matching items found in other eBay areas" in the HTML.
>
>
>
> #!/usr/bin/perl
> # This is a replacement to Hack17
> # The original relied on the WWW::Search::EBay Module
> # Which has been redeveloped to support only Linux/UNIX's !!
> # This code make no use of it and relies on common modules
> # it also emails in a windows environment
> # doesn't makes use of sendmail (doen't exist on windows, unless its 3rd
> party)
> # You will Probably need to install MIME::Lite and possibly Net::SMTP
> # Auhtor Keith Howlette
> # www.keith-howlette.com
> # Use it as you please any bugs to "khowlette<at>bigfoot.com"
> #################################################################
> # Hacking th hack
> # search for more than one item.
> # The search items could be load from a file
> # and used to feed main body of program.
> #
> # I may set this up on a website and allow poeple to submit searches
> # need a good fee linux host that allows perl script to run.
>
> ###################################################################
>
>
> use strict;
> use LWP 5.64;
> use URI;
> use HTML::LinkExtor;
> use HTML::HeadParser;
> use Net::SMTP;
> use MIME::Lite;
>
> # Set too your country e.g. ebaycom.au
> my $country=".co.uk";
>
> my $base="http://search.ebay".$country."/ws/search/SaleSearch";
>
> # Title to search for
> my $title="radeon 9700*";
>
> # Catergory to search get from http://listings.ebay.co.uk > my $cat ="160";
>
> #your email address
> my $email = qw /me@me.com/;
>
> #your mail server
> my $mailsrv =qw /smtp@me.com/;
>
>
> # File to keep items number already seen
> my $localfile="listing.txt";
>
> # declare some vars
> my ($a,$b,$line, $itemnumber,@title,$results,%data,%olditems,$key);
>
> #Set hash to nothing
> %data=();
>
> my $browser = LWP::UserAgent->new;
> # Un comment if you need to use a proxy - replace with real address and port
> #$browser->proxy(['http', 'ftp'], 'http://10.111.10.11:8080/');
> my $url =URI->new($base);
>
> $url->query_form(
> 'sacat'=> $cat,
> 'sasaleclass'=> '2',
> 'satitle'=> $title
> );
>
> # set up the link handler sub
> my $link_extor = HTML::LinkExtor->new(&handle_links);
>
> #get search results
> my $response = $browser->get($url);
>
> #get the links
> $link_extor->parse($response->content);
>
> #get items already seen in hash %olditems
> my %olditems=();
> if (-s $localfile)
> {
>
> open (INFILE,"$localfile");
> while (<INFILE> )
> {
> chomp;
> next if $_ eq "";
> $olditems=1;
> }
> close (INFILE);
> }
>
> # delete items from %data hash already seen
> foreach $key (keys %olditems)
> {
> if (exists($data))
> {
> delete $data;
> }
> }
>
>
> # *** save any remaining new entries to file ***
> open (OUTFILE,">>$localfile");
> my $mailbody="";
>
> foreach $itemnumber (keys %data)
> {
> my $line=&get_title($data);
> print OUTFILE $itemnumber."n";
> #print "Line=".$line."n";
> $mailbody=$mailbody.$line;
> }
> close (OUTFILE);
>
> #send mail
> my $msg = MIME::Lite->new
> (
> To => $email,
> From => $email,
> Subject =>"Ebay Search for [".$title."]",
> Type =>'multipart/related'
> );
>
> $msg->attach(Type => 'text/html', Data => qq{ $mailbody }
> );
>
> MIME::Lite->send('smtp', $mailsrv, Timeout=>60);
>
> $msg->send if $mailbody ne "";
>
>
> ######################################
> sub handle_links
> {
>
> my ($tag, %links)=@_;
> my $key;
> if ($tag eq 'a')
> {
> foreach $key (keys %links)
> {
> #search for links with Viewitem
> if ($key eq 'href')
> {
> if ( $links =~ m/ViewItem/)
> {
> #get the item number from the link
> $links =~ m/item=(d+)/;
>
> $data=$links;
> }
> }
> }
> }
> }
>
> sub get_title($)
> {
>
> my ($page)=@_;
> my $itempage = LWP::UserAgent->new;
> my $item_contents=$itempage->get($page);
>
>
> my $p = HTML::HeadParser->new;
> $p->parse($item_contents->content);
> my $link="<p><a href="$page">".$p->header('Title')."</p>";
> return $link;
>
>
> }
>
>
>
> If anyone could edit the code I would be extremely grateful.
>
> Paul
|
| Similar Threads | Posted | | [RFC] HTML::Dashboard (Spreadsheet-like formatting for HTML tables) | April 16, 2007, 4:50 pm |
| XML::DOM parsing pb | March 9, 2006, 1:27 pm |
| XML Parsing too slow | November 19, 2005, 7:29 am |
| CGI.pm parsing odity | May 16, 2006, 10:01 am |
| Image data parsing | October 27, 2004, 3:36 pm |
| Parsing OpenOffice Spreadsheets | April 25, 2005, 7:23 pm |
| can't find xml-parsing module... | May 27, 2006, 5:30 am |
| Lemur parsing module | June 20, 2006, 10:44 pm |
| XML::Atom::Feed - parsing at all? | January 20, 2008, 5:04 pm |
| Parsing AVI header information | June 8, 2008, 11:08 pm |
|