Table of Contents

Amazon Product Page Checker

General Information

Automatically check an Amazon product page for certain information. (Availability, price, etc)

Checklist


Prep Work: Web Browser

1) In a web browser, visit the Amazon.com product page you want to auto check and save the URL.

2) Copy your user agent string. (To trick the web servers later on)

You can find it by visiting: http://www.useragentstring.com/

Alternatively, the user agent string can be found in Firefox by:


Testing Curl and Grep

1) Using the collected product page URL and user agent string, test a curl against the page.

In this example, I am using a Firefox UA string and checking a PS4 bundle page:

curl -sA "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0" http://www.amazon.com/gp/product/B00O9JLBOC

2) Decide what piece of information from the page you want to watch and test grep.

At the time of the script that I wrote, that PS4 bundle page had a nice big banner on it that said “Sign up to be notified when this item becomes available”. I wanted to receive an e-mail as soon as this text disappeared from the page. (I did not trust that Amazon would actually e-mail me as soon as it was available to buy)

curl -sA "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0" http://www.amazon.com/gp/product/B00O9JLBOC | grep -o "Sign up to be notified when this item becomes available"

The Script

Putting the above curl statement into a working script looks like this:

ps4_checker.sh
#!/bin/bash
 
RESPONSE=$(curl -sA "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0" http://www.amazon.com/gp/product/B00O9JLBOC | grep -io "Sign up to be notified when this item becomes available")
 
if [ "$RESPONSE" != "Sign up to be notified when this item becomes available" ]; then
 /usr/bin/mail -s "PS4 Bundle Available Now!" myname@gmail.com < /home/bill/bin/ps4amazonalert.txt
 crontab -l | sed '/^[^#].*\/home\/bill\/bin\/ps4_checker.sh/s/^/#/' | crontab -
fi

Auto Check it with Cron

Don't forget create the cron entry to have the script execute every 15 mins or so.

crontab -e
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any'). 
# 
# m h  dom mon dow   command
*/15 * * * * /home/bill/bin/ps4_checker.sh