Need Perl program to parse amazon book page
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.
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.
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
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 />
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.
Thanks man, I think I already have LWP installed. When I type:
perl -MLWP -le "print(LWP->VERSION)"
I get 5.803
Ok, are the utilities installed? Does the command line: wget work?
I guess they’re not a part of LWP no more.
Alright, I’ve got LWP v5.803, wget.exe v1.10.2, and Perl v5.8.7
Where are you man? Don’t give up on meh!
Please respond.
Thanks!
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:
|
#!/usr/bin/perl use warnings; use LWP; # Get args – url and price # Create a user agent object # Create a request # Pass request to the user agent and get a response back # Check the outcome of the response # If we got our price entry… my $price; if($_ =~ /class="priceLarge">$d+.d+/) # We got our price, and its less than our limit. Notify chode. } @lines; } |
what happened to that grep one-liner
P.S. I told you that php would be easier than Perl LWP.
It works! I’ve been needing something like this for a while now, thanks!
And no, I can promise you this wasn’t homework.
|
It works! I’ve been needing something like this for a while now, thanks!
And no, I can promise you this wasn’t homework. |
Buy me a subscription to OT.
ok
<?
# 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]}nn";
?>
I’m broke man, I don’t even have a sub… but I appreciate your help.
|
ok
<?
# 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]}nn";
?>
|
Your skills are impressive, but I wanted it in perl… BTW have you seen your boy Fred Durst lately?
|
ok
<?
# 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]}nn";
?>
|
I handled errors bro. You didn’t.
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.
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.
October 22nd, 2009 at 6:05 am
Remarkably, that fear lingers on– for years after our school days are distant memories. ,
October 23rd, 2009 at 5:18 am
The offer of praise is a relatively inexpensive means of payment; fame is a cheap date for the fans, so to speak. ,