Product stock monitoring is the job of reading the stock status on a product page at regular intervals and comparing it with the previous read. Most stores publish that status in JSON-LD embedded in the page, in schema.org's availability field. The value is kept separately for each variant. That is the trap: a product can show "in stock" while the size you want is sold out. This post covers where stock data sits on the page, how often to check, how to send an alert when the status changes and how stock differs by country.
Sources of stock data
Stock status lives in three places on a page, and they differ in how well they hold up. The seller's own channel is the most reliable. If you are the seller or supplier, or the store gives you a product feed, use that first. A feed delivers stock data in one file, without opening a single page.
Without a feed, the next place is JSON-LD. This is structured data inside a <script type="application/ld+json"> tag, written for search engines. Product name, price and stock sit there in labelled fields. We explained the format itself in What Is Schema Markup?.
The last place is the "Add to cart" button or the "Sold out" label on screen. When the design changes, the button's class name changes too, and the script breaks silently.
| Source | What it gives | Durability |
|---|---|---|
| Official API or product feed | Every product, in one request | High |
JSON-LD availability | Status per product and variant | Medium-high |
| Visible button and label | Whatever the screen says | Low |
Use the button only for verification. Take the main signal from JSON-LD.
availability values
The availability field is not free text. It is a value from schema.org's ItemAvailability list, which has twelve values. A store may write the value as a full URL (https://schema.org/InStock) or as a short name (InStock). Some older pages use http://. Before comparing, cut the value down to what follows the last /.
For alerts, grouping the twelve values into four is enough:
| Group | Values | Alert meaning |
|---|---|---|
| Buyable | InStock, LimitedAvailability, OnlineOnly, MadeToOrder | Back in stock |
| Taking orders | PreOrder, PreSale, BackOrder | Orders open, delivery later |
| Not buyable | OutOfStock, SoldOut, Discontinued | Sold out |
| Not buyable online | InStoreOnly, Reserved | Not sold on the site |
LimitedAvailability may deserve its own alert. Low stock is the last signal before a sellout. Discontinued is a reason to stop monitoring. Stop checking that product.
Stock per variant
For products with a size and colour choice, stock is kept per variant, not per product. JSON-LD models this with a ProductGroup. The group carries the shared data, and each Product under hasVariant carries its own offers field and its own availability value. In the example in Google's product variant documentation, one size shows BackOrder and the others InStock.
This structure shapes the parsing code directly. A script that takes the first availability value and stops still says "in stock" when size M sells out. Store each variant under its own key. The best key is the sku field. Without sku, the variant's name or url field works.
Some stores give each variant its own URL (such as ?size=m). The page then shows a single product, and the URL decides the variant. Add the variant URLs to your watch list one by one.
Check frequency and conditional requests
The product's value and how fast its stock moves set the check frequency. A limited run that sells out in minutes and a product that sits on the shelf for weeks do not deserve the same interval. Check fast movers often and the rest rarely. Read the site's robots.txt first and follow its terms. We explained how the file is read in our robots.txt post.
Conditional requests cut the cost of frequent checks. The server can send an ETag value or a Last-Modified date in the response. You send that value back in the next request with an If-None-Match or If-Modified-Since header. If the page has not changed, the server skips the body and returns 304 Not Modified.
Know two things. Requests does not send these headers on its own; you have to store the value and add it yourself. And not every server sends an ETag. Pages built per visitor often return the full body every time. In that case a conditional request does no harm. It just brings no gain.
Alert on change
An alert comes from the difference between the new read and the previous one. A script that messages "in stock" on every check gets muted on day one. Report only transitions: OutOfStock to InStock, InStock to SoldOut. The first run only records, because there is no old value to compare.
The function below reads every JSON-LD block on the page, walks into the variants inside @graph and ProductGroup, and builds a {sku: state} dictionary for each offer. check sends a conditional request with the stored ETag, compares the states with the previous record and returns only the variants that changed.
import json
import re
from pathlib import Path
import requests
PROXY = "http://user:pass@pr.proxynet.io:8000"
URL = "https://shop.example/product/123"
STATE_FILE = Path("stock-state.json")
JSONLD = re.compile(
r"<script[^>]*application/ld\+json[^>]*>(.*?)</script>", re.S | re.I
)
def products(data):
"""Yields the Product nodes in JSON-LD, variants included, in order."""
if isinstance(data, list):
for part in data:
yield from products(part)
return
if not isinstance(data, dict):
return
yield from products(data.get("@graph", []))
kind = data.get("@type")
kinds = kind if isinstance(kind, list) else [kind]
if "ProductGroup" in kinds:
yield from products(data.get("hasVariant", []))
elif "Product" in kinds:
yield data
def stock_states(html):
"""Returns {sku: state} for each offer on the page, e.g. {"TS-M": "InStock"}."""
states = {}
for block in JSONLD.findall(html):
try:
data = json.loads(block)
except ValueError:
continue # broken block, move to the next one
for product in products(data):
offers = product.get("offers") or []
if isinstance(offers, dict):
offers = [offers]
for offer in offers:
state = str(offer.get("availability", "")).rsplit("/", 1)[-1]
key = offer.get("sku") or product.get("sku") or product.get("name")
if state:
states[key] = state
return states
def check(session, url, record):
"""Returns changed variants as [(sku, old, new)] and updates the record."""
headers = {}
if record.get("etag"):
headers["If-None-Match"] = record["etag"]
if record.get("last_modified"):
headers["If-Modified-Since"] = record["last_modified"]
response = session.get(url, headers=headers, timeout=20)
if response.status_code == 304:
return [] # page unchanged, no body sent
response.raise_for_status()
new = stock_states(response.text)
if not new:
raise ValueError("no availability found in JSON-LD")
old = record.get("states", {})
changed = [
(sku, old[sku], state)
for sku, state in new.items()
if sku in old and old[sku] != state
]
record.update(
etag=response.headers.get("ETag"),
last_modified=response.headers.get("Last-Modified"),
states=new,
)
return changed
if __name__ == "__main__":
session = requests.Session()
session.proxies = {"http": PROXY, "https": PROXY}
record = json.loads(STATE_FILE.read_text()) if STATE_FILE.exists() else {}
for sku, old, new in check(session, URL, record):
print(f"{sku}: {old} -> {new}") # hook your alert in here
STATE_FILE.write_text(json.dumps(record, indent=2))On an empty result the function raises an error. That is on purpose. If the page structure changes and an empty dictionary gets saved, every variant looks "new" on the next read and a real sellout slips through. Hook the print line to your own channel: email, a chat webhook or a spreadsheet row.
Stock by country
Many stores show stock based on the visitor's country. When the warehouse, delivery zone and country store differ, the same product returns InStock in one country and OutOfStock in another. The site usually decides this by IP address. A script checking from your own country does not see the stock of the market you track.
That is the proxy's role here: sending the request from the location of a visitor in that market. We explained how country targeting works in Proxy Country and City Targeting. A Residential Proxy carrying home connection IPs lets you see the page the site shows real visitors.
Once you pick a country, split the record by country too. If you read the same URL from two countries and write to one record, every check produces a "change". Make the key the (url, country) pair. The ETag value is tied to that pair as well, because the two countries get different pages.
Troubleshooting
Most stock monitoring errors are silent: the script runs but records the wrong result.
ValueError: no availability found in JSON-LD. The block is not in the raw HTML. Either JavaScript adds it later, or the site uses microdata (itemprop="availability"). Open the page source in a browser and search foravailability.- Five sizes, one state in the record. The offers carry no
sku, and the key falls back to the product name. When variants share a name, they overwrite each other. Build the key fromurlor the size field. - No
304ever. The server sends noETag, or changes it on every response. Check theetagfield in the record. - A change reported on every check. Requests leave from different countries. Pin the country and split the record by country.
407 Proxy Authentication Required. Wrong username or password. If the password contains@, write it as%40.429 Too Many Requests. The interval is too short. Lower the check frequency.
How we tested
We ran the code on 2 December 2026 with Python 3.13.17 and Requests 2.34.2. A local test site returned a three-size ProductGroup inside @graph and an ETag header. One size's value used the short name, the others the full URL. Requests went through a local HTTP proxy that required Basic authentication and logged every incoming request.
The first run recorded three states and produced no alert. On the second run the request went out with If-None-Match, and the server returned 304. After we changed the stock file, the third run reported only two transitions: TS-M: OutOfStock -> InStock and TS-L: InStock -> SoldOut. With a wrong password the request failed with 407.
The bottom line
Read stock from JSON-LD, not the visible button, store each variant under its own key and report only transitions. On sites that show stock by country, send the request from that country and split the record by country. The product side of this use case is on the e-commerce proxy page. Above all, if the seller has an official API or product feed, do not start reading pages at all.
Sources
- ItemAvailability, value list: schema.org
- HTTP conditional requests: developer.mozilla.org
- Merchant listing (Product, Offer) structured data: developers.google.com
- Product variant structured data (ProductGroup, Product): developers.google.com
Frequently asked questions
Which field should I read for stock monitoring?
The availability field. It sits in the Offer object inside JSON-LD and takes one of the schema.org values: InStock, OutOfStock, PreOrder and so on. In products with variants, each variant has its own offers field. Read the offer for the size or colour you track, not the product's overall status, and store each one separately by sku.
Is there a difference between OutOfStock and SoldOut?
Yes, but for alerts both belong to the same group. Both say the product cannot be bought right now. Stores pick these values by their own rules. One site may write OutOfStock, another SoldOut. Put both in the "not buyable" group in your script. Discontinued is different: the product is no longer sold, and it makes sense to stop monitoring.
Where do I read stock if the page has no JSON-LD?
Look at microdata first. Some sites write the same data into the HTML with the itemprop="availability" attribute. If that is missing too, the visible "Add to cart" button or "Sold out" label remains. This route breaks when the design changes. Verify the selector regularly against a control page, and set up the script to fail when the result is empty.
How many minutes apart should I check?
It depends on how fast the product sells out. Limited items that go in minutes need frequent checks; for products that sit on the shelf for weeks, a few reads a day are enough. Follow the site's robots.txt and terms. If you get 429, widen the interval. With conditional requests an unchanged page returns 304 without a body, which puts less load on the server.
Does ETag work on every site?
No. ETag and Last-Modified are optional headers the server may send. They are common on static or cached pages. On pages built per visitor they are often missing or change with every response. Your code should handle both cases: send a conditional request when the header exists, and read the full page when it does not.
Why is a proxy needed for stock monitoring?
It is needed on sites that show stock by country. The site usually picks stock and delivery data based on the visitor's IP address. To see another market's stock, the request has to come from that country. On a site that sells in one country and shows everyone the same stock, a proxy does not change the stock signal. There, try the official API and product feed first.




