Create RSS Feeds from Amazon Listings

Published in: Amazon - PHP - RSS

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.


  $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></link>';
  $head .= '<description>Amazon RSS Feed</description>';

  $url = "";

  $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   = "" . $ASIN . "/?tag=ctrlqorg-20";
                $img   = "" . $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  = "" . $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);

📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: Amazon - PHP - RSS

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

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. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube