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 is a web geek, solo entrepreneur and loves making things on the Internet. Google recently awarded him the Google Developer Expert and Google Cloud Champion title for his work on Google Workspace and Google Apps Script.

Awards & Recognition

Google Developer Expert

Google Developer Expert

Google awarded us the Developer Expert title recogizing our work in Workspace

ProductHunt Golden Kitty

ProductHunt Golden Kitty

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

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional title for 5 years in a row

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator award for technical expertise

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

We will never send any spam emails. Promise 🫶🏻