Need Perl program to parse amazon book page

Discussion in 'OT Technology' started by SubOptimal, Jul 1, 2008.

  1. SubOptimal

    SubOptimal New Member

    Joined:
    Jun 27, 2002
    Messages:
    4,410
    Likes Received:
    0
    Can anyone of you leet hax0rs hack up a Perl program that can parse an Amazon book page and notify me when a used book is less than a certain amount? I could run it through the Windows scheduler to check every 5 minutes and it would help a lot.
     
  2. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    I get paid to do that. You can lookup WWW::Mechanize or LWP and do it yourself, though.

    In fact, if you can show me the chunk of HTML the price on your page is in and the url, I can probably do it in shell with grep as a one-liner. That I could do for you.
     
  3. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    but PHP is so much easier than LWP

    and why use grep when you can use ack, it's 25% more efficient with it's lack of 1 letter :mamoru:
     
    Last edited: Jul 1, 2008
  4. SubOptimal

    SubOptimal New Member

    Joined:
    Jun 27, 2002
    Messages:
    4,410
    Likes Received:
    0
    Ahh I never thought about just using grep... I'm on Windows XP so what would you recommend I use to download the page?

    Here is the part of the page I need to match on..

    used & new</a> available from <span class="price">$53.96</span><br />
     
  5. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    I saw that. And PHP is not so much easier than LWP. PHP is much harder than LWP. With LWP you do this:

    wget url

    Real hard, right?

    OP: Download and install LWP's wget program, and ActivePerl and I will do it for you.
     
  6. SubOptimal

    SubOptimal New Member

    Joined:
    Jun 27, 2002
    Messages:
    4,410
    Likes Received:
    0
    Thanks man, I think I already have LWP installed. When I type:

    perl -MLWP -le "print(LWP->VERSION)"

    I get 5.803
     
  7. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Ok, are the utilities installed? Does the command line: wget work?
     
  8. SubOptimal

    SubOptimal New Member

    Joined:
    Jun 27, 2002
    Messages:
    4,410
    Likes Received:
    0
    No, I don't think so, how can I install them?
     
    Last edited: Jul 2, 2008
  9. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
  10. SubOptimal

    SubOptimal New Member

    Joined:
    Jun 27, 2002
    Messages:
    4,410
    Likes Received:
    0
    Alright, I've got LWP v5.803, wget.exe v1.10.2, and Perl v5.8.7
     
  11. SubOptimal

    SubOptimal New Member

    Joined:
    Jun 27, 2002
    Messages:
    4,410
    Likes Received:
    0
    Where are you man? Don't give up on meh!

    Please respond.
     
  12. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Ok ok I'm back I'll do it.
     
  13. SubOptimal

    SubOptimal New Member

    Joined:
    Jun 27, 2002
    Messages:
    4,410
    Likes Received:
    0
    Thanks! :bowdown: :bowdown: :bowdown: :bowdown:
     
  14. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    I can't believe I did this for you. I should have used an html parser, or whipped up an elite one liner, but wtf this works:

     
    Last edited: Jul 4, 2008
  15. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    BTW, if that was homework I'll murder you.
     
  16. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    what happened to that grep one-liner :mamoru:

    P.S. I told you that php would be easier than Perl LWP. :p
     
  17. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Prove it.
     
  18. SubOptimal

    SubOptimal New Member

    Joined:
    Jun 27, 2002
    Messages:
    4,410
    Likes Received:
    0
    It works! I've been needing something like this for a while now, thanks! :bowdown::bowdown::bowdown::bowdown:

    And no, I can promise you this wasn't homework. :o
     
  19. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Buy me a subscription to OT.
     
  20. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah

    ok

    Code:
    <?
         # usage: grab.php [link] [price]
         preg_match('#class="priceLarge">\$(\d+\.\d+)#',file_get_contents($argv[1]),$m);
         if($m[1]<$argv[2]) echo "\nFor url {$argv[1]} found a price of \${$m[1]} which is \$".($argv[2] - $m[1])." less than our limit of \${$argv[2]}\n\n";
    ?>
     
  21. SubOptimal

    SubOptimal New Member

    Joined:
    Jun 27, 2002
    Messages:
    4,410
    Likes Received:
    0
    I'm broke man, I don't even have a sub... but I appreciate your help. :hs:

    Your skills are impressive, but I wanted it in perl... BTW have you seen your boy Fred Durst lately? http://www.tomgreen.com/?video=1145
     
  22. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    I handled errors bro. You didn't.
     
  23. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    even if i handled errors it'd still be like 1/4 the size of all that perl code. i'm not trying to brag about skills, just showing that when it comes to anything web related PHP has the upperhand on Perl. PHP was designed for the web whereas Perl was not.

    My first Job at 16 was as a data miner programming in Perl and later i started doing Perl/CGI, but PHP is definitely more robust when it comes to the web. I still use Perl for most of my local scripting but when it comes to web stuff, PHP is great.
     

Share This Page