Create RSS Feeds from Amazon Listings

If an Amazon Category page does not offer RSS feeds, you can use PHP to easily create one. The PHP snippet below will download a page from the Amazon website and converts the products into an RSS feed so you can easily track when new items are added to that category.

The RSS feed will have the product name, the title, the permalink (URL) and the thumbnail image.

<?php

  $now   = date("D, d M Y H:i:s T");
  $ASIN  = $url = $img = $title = $bio = $name = "";

  $head = '<?xml version="1.0" encoding="ISO-8859-1"?>';
  $head .= '<rss version="2.0">';
  $head .= '<channel>';
  $head .= '<title>Amazon </title>';
  $head .= '<link>http://www.amazon.com</link>';
  $head .= '<description>Amazon RSS Feed</description>';

  $url = "http://www.amazon.com/Best-Sellers-Kindle-Store/zgbs/digital-text/";

  $text = file_get_html($url);

  foreach ($text->find("div.zg_item_compact") as $class) {
    foreach ($class->find('strong.price') as $price) {
      if ($price->plaintext == "Free") {
              $rssfeed .= '<item>';
              foreach ($class->find("div.zg_title a") as $book) {
                preg_match("/\/dp\/(.*)\/ref/", $book->href, $matches);
                $ASIN  = trim($matches[1]);
                $url   = "http://www.amazon.com/dp/" . $ASIN . "/?tag=ctrlqorg-20";
                $img   = "http://images.amazon.com/images/P/" . $ASIN . ".01.LZZZZZZZ.jpg";
                $title = htmlentities(trim($book->plaintext));
                $rssfeed .= '<title>' . $title . '</title>';
                $rssfeed .= '<link>' . $url . '</link>';
                $rssfeed .= '<guid isPermaLink="true">' . $url . '</guid>';
                $rssfeed .= '<description>';
              }
              foreach ($class->find("div.zg_byline a") as $author) {
                  $bio  = "http://www.amazon.com" . $author->href . "/?tag=publisherapi-20";
                  $name = htmlentities(trim($author->plaintext));
                  $rssfeed .= 'By <a href="' . $authorURL . '">' . $name . '</a>';
              }
              $rssfeed .= '</description>';
              $rssfeed .= '<pubDate>' . $now . '</pubDate>';
              $rssfeed .= '</item>';
          }
      }
  }

  $footer  = '</channel></rss>';
  $rssfeed = $head . $rssfeed . $footer;
  $fh      = fopen("amazon.rss", "w");

  fwrite($fh, $rssfeed);
  fclose($fh);

?>
Amit Agarwal

Amit Agarwal

Google Developer Expert, Google Cloud Champion

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.

Amit has developed several popular Google add-ons including Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Awards & Titles

Digital Inspiration has won several awards since it's launch in 2004.

Google Developer Expert

Google Developer Expert

Google awarded us the Google Developer Expert award recogizing our work in Google Workspace.

ProductHunt Golden Kitty

ProductHunt Golden Kitty

Our Gmail tool won the Lifehack of the Year award at ProductHunt Golden Kitty Awards in 2017.

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional (MVP) title for 5 years in a row.

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator title recognizing our technical skill and expertise.

Email Newsletter

Sign up for our email newsletter to stay up to date.

We will never send any spam emails. Promise.