Site icon EASY2DIGITAL

Chapter 17: Amazon Price Tracker, Get the Up-to-date Product Market Value Using ASIN, Oauth2Client, and Google Sheet

Google Sheets ImportXML in a way can do a similar task as well as Python product pricing tracker. However, every Google sheet only allows running 50 cells of importXML at the same time. Frankly, it’s not sufficient if you are fetching different dimensional data. Being said, it is much easier and less complex. If you are interested, please check out my article regarding Google Sheets ImportXML.

Google Sheets ImportXML – Automatically Scrape Web and Collect Product Price Info

In this chapter, I would walk you through how to use Python to create a more all-rounded Amazon product price tracker. This tracker can be extended to update the data automatically without any manual work. Before sharing the schedule script in the next Python Tutorial, you can learn how to visit product pages by using Asin, and find, fetch and upload the price data to Google Sheets.

Table of Contents: Amazon Price Tracker Using Python

Install gspread and Oauth2Client Module

Gspread is a super simple Google Sheets Python API. You can continue to use Google Sheets API as I shared previously, for reading and writing new sheets and data. This article would use gspread, and basically, the methodology is similar. But the methods and logic are simple

First thing first, we need to install gspread in your Macbook terminal

Pip3 Install gspread

Then, we need to install the upgraded OauthClient module. This is for you to connect the Google Sheet API and activate the service account JSON file.

Pip3 Install --upgrade oauth2client

Third, we need to create a Google API project and service account. For more details, please check out the other article that I shared previously.

Defining the Google Sheet API scope is necessary. As we need to connect with Google drive as well, there are 3 scopes for creating an Amazon price tracker. Below I create a variable called scope.

scope = ['https://www.googleapis.com/auth/spreadsheets',

'https://www.googleapis.com/auth/drive.file',

'https://www.googleapis.com/auth/drive']

Then, you download the JSON file after having created a service account in Google API. We would create a variable called creds and add the JSON file name in the below coding.

creds = ServiceAccountCredentials.from_json_keyfile_name('ajljou4098erqwie08234.json',scope)

Last but not least, gspread is used to read, and update the Google Sheets. So we can create a variable called client, and authorize creds to this variable.

client = gspread.authorize(creds)

Get and Read the scraped Amazon Product ASIN

In Python Tutorial 16, we’ve scraped a bulk of product information, that includes ASIN. So along with the amazon product scraper, we can continue to use the same Google sheet file.

First thing first, we need to open the Google sheet file, where we use the open method.

sh = client.open('AmazonPriceTracker')

Then, we need to select the Google sheet tab that stores the product asin by using the get_worksheet method. Here the value starts from 0. 0 represents the 1st tab and then is 1, 2, and so on.

worksheet = sh.get_worksheet(2)

Depending on which column or row we save the asin data, we can leverage the methods of either col_value or row_value. For more methods given by gspread, please check out the documentation

values_list = worksheet.col_values(2)

Visit the Product Page and Fetch the Price Data

Now, value_list has got the scraped product asin. The next step is to loop and visit the product page for fetching the pricing data. In the price element, there are some places showing the product pricing. It depends on the Amazon page update. In a way, there are 4 places, which are the list price, current price, buybox price, and new buybox price. Here would show the list price for the example.

Again, as mentioned in the previous Python Tutorial, Amazon bans the requests and BeautifulSoup directly visits the pages. So we need to leverage selenium. For more details, please check out the previous Python Tutorial.

Chapter 16 – Amazon Product Scraper Using Selenium, BeautifulSoup, and Easy2Digital APIs

First thing first, we need to create a loop and use selenium, BeautifulSoup to gain the price HTML information.

for asin in values_list:
      competitor = driver.get(f'https://www.amazon.com/dp/{asin}')
      soup = BeautifulSoup(driver.page_source, 'html.parser')
      time.sleep(5)

Then, under the parent tree of the asin looping, we need to find the path of the pricing data and create a looping for it as well. As you can see, the list price element is located in the span and the class of priceBlockStrikePriceString a-text-strike. So let us write the codes as listed below

for price in soup:

     try:
         ListPrice = price.find('span','priceBlockStrikePriceString a-text-strike').text.replace('$','')
     except Exception as e:
         ListPrice = '0'

Just kindly remind me that in the try and except, it’s better to set the none into a number, such as 0. It facilitates you to find the lowest price later on in the price tracker.

Append and Reset the Fetched Data Uploaded to Google Sheet

First thing, we can create an empty value of variable amazonSERP. This is for appending the information later on.

As you can see, I assume we collect 4 price data and we can name them and group them in the variable of element_info. Then, in the Pandas module, we can append and frame this information in an organized format, by using append() and dataframe() methods.

element_info = {
"ListPrice": ListPrice,
"PagePrice": priceA,
"BuyboxPrice": priceBuybox,
"NewBuyboxPrice": NewpriceBuybox
}

amazonSERP.append(element_info)

df = pd.DataFrame(amazonSERP)

For updates to the Google sheets, gspread has a method of value_update, that includes 3 parts you can plug into value. They are the Sheet location, parameters, and body for the value to update.

As gspread requires an assigned format, we need to reset the current orders and formats by using reset_index() and values.tolist() method.

value_list2 = sh.values_update('ProductPagePricingTracker!D1', params={'valueInputOption': 'USER_ENTERED'},body=dict(values=df.T.reset_index().T.values.tolist()))

Up-to-date Product Market Value in the P&L Calculator

Below the D to G column, it shows the scraped different pricing data on an Amazon product page. Of course, we don’t recommend you plug these data into your P&L calculator. You can use the min() method to select the lowest one. So you can refer to the lowest one compared with yours.

In the P&L calculator, apart from the flat and variable cost elements, you can observe the pricing market value of your products. As pricing is one of the key elements affecting the conversation rate, you should keep eye on that. The up-to-date information helps you make a better decision on the selling strategies and the digital advertising bidding and budget allocation.

For the retail market value in terms of pricing, the higher percentage number represents the more competitive pricing point in the competition space. You can set up conditional formatting, so you can spot immediately when the number is highlighted in a red color. That means something is happening. For example, your competitors might be doing promotions.

Full Python Script of Amazon Product Price Tracker

If you would like to have the full version of the Python Script of Amazon Product Price Tracker, please subscribe to our newsletter by adding the message “Chapter 17”. We would send you the script immediately to your mailbox.

Contact us

I hope you enjoy reading Chapter 17: Amazon Price Tracker, Get the Up-to-date Product Market Value Using ASIN, Oauth2Client, and Google Sheets. If you did, please support us by doing one of the things listed below, because it always helps out our channel.

FAQ:

Q1: What is an Amazon Price Tracker?

A: An Amazon Price Tracker is a tool that allows users to monitor the prices of products on Amazon and track any changes in real-time.

Q2: How does an Amazon Price Tracker work?

A: An Amazon Price Tracker works by regularly scanning the prices of products on Amazon and storing this data. It then provides users with insights and alerts regarding price fluctuations.

Q3: What are the benefits of using an Amazon Price Tracker?

A: Using an Amazon Price Tracker can help users save money by identifying price drops and allowing them to purchase products at the best possible price. It also helps users make informed buying decisions by providing historical price data and trends.

Q4: Can an Amazon Price Tracker track prices of all products on Amazon?

A: Yes, an Amazon Price Tracker can track prices of almost all products available on Amazon, including both popular and niche items.

Q5: Is an Amazon Price Tracker free to use?

A: Some Amazon Price Trackers offer free versions with limited features, while others require a subscription or payment for access to advanced features and enhanced data insights.

Q6: Can an Amazon Price Tracker be used on mobile devices?

A: Yes, many Amazon Price Trackers have mobile apps or are mobile-friendly, allowing users to conveniently track prices and receive alerts on their smartphones or tablets.

Q7: What kind of alerts can an Amazon Price Tracker provide?

A: An Amazon Price Tracker can provide alerts for price drops, price increases, and when a product reaches a user-defined target price. It can also notify users of deals, discounts, and limited-time offers.

Q8: Is it possible to set price alerts for specific products with an Amazon Price Tracker?

A: Yes, users can set price alerts for specific products they are interested in. The Amazon Price Tracker will then notify them when the price of the selected product changes.

Q9: Can an Amazon Price Tracker track prices on international Amazon websites?

A: Yes, many Amazon Price Trackers have the ability to track prices on various international Amazon websites, allowing users to monitor prices across different regions and marketplaces.

Q10: Is my personal information secure when using an Amazon Price Tracker?

A: Reputable Amazon Price Trackers take user privacy and data security seriously. They use encryption and adhere to strict privacy policies to ensure that personal information is protected.

Amazon API Endpoint Recommendation

Keyword Data Estimator API

Price: US$54

Keyword data estimator can generate keyword avg.monthly traffic and CPC. Keyword estimator can generate the keyword data by country and channel using a keyword query. Options of search engine channel include Google, Bing, Amazon. 4 languages are doable which are English, Japanese, Simplified Chinese and Traditional Chinese

More API options from the Amazon collection. 

SAVE UP TO 50% and EXPLORE MORE!

Exit mobile version