Professional Web Applications Themes

Html parsing - Macromedia Director Lingo

How can I obtain the body copy text from an html file imported into director using getnetText. I have imported in the file which is sitting in a text file. I need to keep all the style the same as the html page. I think parsing the file using offset may be the method but cannot find any info on this. Please help. Thanks...

  1. #1

    Default Html parsing


    How can I obtain the body copy text from an html file imported into director
    using getnetText.

    I have imported in the file which is sitting in a text file. I need to keep
    all the style the same as the html page. I think parsing the file using
    offset may be the method but cannot find any info on this.

    Please help.

    Thanks

    j Guest

  2. #2

    Default Re: Html parsing

    Why p it? Why not just display the HTML using one of the Xtra's, or even
    setting the HTML property of a text member to your imported file. Text works
    fine... images don't, but this may work fine for your app. If not, I'd
    suggest just using an Xtra it'll be much easier than trying to write a
    pr.

    --


    Dave Mennenoh
    [url]http://www.crackconspiracy.com/~davem[/url]


    Dave Mennenoh Guest

  3. #3

    Default HTML parsing


    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 ps 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
    # [url]www.keith-howlette.com[/url]
    # 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::HeadPr;
    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 [url]http://listings.ebay.co.uk[/url]
    my $cat ="160";

    #your email address
    my $email = qw /meme.com/;

    #your mail server
    my $mailsrv =qw /smtpme.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->p($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{$key}))
    {
    delete $data{$key};
    }
    }


    # *** save any remaining new entries to file ***
    open (OUTFILE,">>$localfile");
    my $mailbody="";

    foreach $itemnumber (keys %data)
    {
    my $line=&get_title($data{$itemnumber});
    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{$key} =~ m/ViewItem/)
    {
    #get the item number from the link
    $links{$key} =~ m/item=(\d+)/;

    $data{$1}=$links{$key};
    }
    }
    }
    }
    }

    sub get_title($)
    {

    my ($page)=_;
    my $itempage = LWP::UserAgent->new;
    my $item_contents=$itempage->get($page);


    my $p = HTML::HeadPr->new;
    $p->p($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


    Paul Bell Guest

  4. #4

    Default Re: HTML parsing



    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 ps 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::Pr
    directly so that you can devine a callback for text too. To see how to
    achive the functionality of HTML::LinkExtor using HTML::Pr 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
    > # [url]www.keith-howlette.com[/url]
    > # 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::HeadPr;
    > 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 [url]http://listings.ebay.co.uk[/url]
    > my $cat ="160";
    >
    > #your email address
    > my $email = qw /meme.com/;
    Using q rather than qw would be more ideomatic for a scalar.
    >
    > #your mail server
    > my $mailsrv =qw /smtpme.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::Pr->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->p($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{$key}))
    > {
    > delete $data{$key};
    > }
    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{$itemnumber});
    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{$key} =~ m/ViewItem/)
    > {
    > #get the item number from the link
    > $links{$key} =~ m/item=(\d+)/;
    >
    > $data{$1}=$links{$key};
    You should never use $1 without checking the match succeded.

    my $href = $links{href};
    $data{$1}= $href if $href && $href =~ /ViewItem.*item=(\d+)/;

    Or since you are now calling this callback directly from HTML::Pr
    not HTML::LinkExtor you'd need to make the link absolute yourself.

    $data{$1}= 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.

    Brian McCauley Guest

  5. #5

    Default Re: HTML parsing

    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 [url]www.keith-howlette.com[/url] - 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 pr after the phrase I would
    be very grateful if someone could post a solution.

    Thanks,

    Paul



    "Brian McCauley" <nobullmail.com> wrote in message
    news:d1mp73$a9g$1sun3.bham.ac.uk...
    >
    >
    > 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 ps 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::Pr
    > directly so that you can devine a callback for text too. To see how to
    > achive the functionality of HTML::LinkExtor using HTML::Pr 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
    >> # [url]www.keith-howlette.com[/url]
    >> # 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::HeadPr;
    >> 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 [url]http://listings.ebay.co.uk[/url]
    >> my $cat ="160";
    >>
    >> #your email address
    >> my $email = qw /meme.com/;
    >
    > Using q rather than qw would be more ideomatic for a scalar.
    >>
    >> #your mail server
    >> my $mailsrv =qw /smtpme.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::Pr->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->p($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{$key}))
    >> {
    >> delete $data{$key};
    >> }
    >
    > 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{$itemnumber});
    >
    > 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{$key} =~ m/ViewItem/)
    >> {
    >> #get the item number from the link
    >> $links{$key} =~ m/item=(\d+)/;
    >>
    >> $data{$1}=$links{$key};
    >
    > You should never use $1 without checking the match succeded.
    >
    > my $href = $links{href};
    > $data{$1}= $href if $href && $href =~ /ViewItem.*item=(\d+)/;
    >
    > Or since you are now calling this callback directly from HTML::Pr not
    > HTML::LinkExtor you'd need to make the link absolute yourself.
    >
    > $data{$1}= 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.
    >

    Paul Bell Guest

  6. #6

    Default Re: HTML parsing

    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 ps 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 [url]http://johnbokma.com/perl/froogle-script.html[/url]

    for an example.

    --
    John Small Perl scripts: [url]http://johnbokma.com/perl/[/url]
    Perl programmer available: [url]http://castleamber.com/[/url]
    Happy Customers: [url]http://castleamber.com/testimonials.html[/url]

    John Bokma Guest

  7. #7

    Default Re: HTML parsing

    Hi

    I've posted a new version of the code on my website
    [url]http://www.keith-howlette.com/download/hack17v101.pl[/url] 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

    "Paul Bell" <pauliNcOoSmPpAlMy.co.uk> wrote in message news:<3a83lvF66tjseU1individual.net>...
    > 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 ps 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
    > # [url]www.keith-howlette.com[/url]
    > # 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::HeadPr;
    > 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 [url]http://listings.ebay.co.uk[/url]
    > my $cat ="160";
    >
    > #your email address
    > my $email = qw /meme.com/;
    >
    > #your mail server
    > my $mailsrv =qw /smtpme.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->p($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{$key}))
    > {
    > delete $data{$key};
    > }
    > }
    >
    >
    > # *** save any remaining new entries to file ***
    > open (OUTFILE,">>$localfile");
    > my $mailbody="";
    >
    > foreach $itemnumber (keys %data)
    > {
    > my $line=&get_title($data{$itemnumber});
    > 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{$key} =~ m/ViewItem/)
    > {
    > #get the item number from the link
    > $links{$key} =~ m/item=(\d+)/;
    >
    > $data{$1}=$links{$key};
    > }
    > }
    > }
    > }
    > }
    >
    > sub get_title($)
    > {
    >
    > my ($page)=_;
    > my $itempage = LWP::UserAgent->new;
    > my $item_contents=$itempage->get($page);
    >
    >
    > my $p = HTML::HeadPr->new;
    > $p->p($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
    Keith Howlette Guest

Similar Threads

  1. Including / Parsing CF in HTML
    By RazorX in forum Coldfusion - Getting Started
    Replies: 4
    Last Post: March 1st, 01:24 PM
  2. Parsing multipart html content
    By Christopher Stanton in forum PERL Beginners
    Replies: 6
    Last Post: November 12th, 04:41 AM
  3. Parsing Html
    By Colum in forum PHP Development
    Replies: 2
    Last Post: October 30th, 10:22 PM
  4. nested HTML parsing
    By Brian McCauley in forum PERL Miscellaneous
    Replies: 4
    Last Post: August 8th, 03:27 PM
  5. HTML File Parsing
    By Raja Balaji R in forum ASP.NET General
    Replies: 1
    Last Post: August 3rd, 05:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139