Package: ecommerce-exporter
ecommerce-exporterecommerce-exporter is aprometheusexporter that webscrape the storefront of various e-commerces and expose the price of their products as prometheus metrics. These metrics can then be used to graph the pricing evolution over time, send alerts when the price drop, or to easily compare the price of a product on many e-commerces at once.InstallAn aarch64 and an amd64 docker images are available ondocker hub. You can pull it using:dockerpullbadjware/ecommerce-exporterThis is the recommended way of running the exporter.UsageDownload theexample configuration fileand edit it to configure the e-commerce sites you wish to scrape. You can configure multiple products and multiple targets in the same configuration file.Assuming you named your configuration fileecommerce-exporter.yml, you can use the following command to run the exporter with docker:dockerrun-v"$PWD/ecommerce-exporter.yml:/ecommerce-exporter.yml"-p8000:8000badjware/ecommerce-exporterThe prices of the configured products will start being scraped and exposed onhttp://localhost:8000/metrics. You can then configureprometheus to scrape that endpoint. It is recommended to set the scrape interval to be the same as the webscrape interval of the exporter (15m by default).A full list of available flags can be printed using-h:usage: An utility to scrape e-commerce product price and expose them as prometheus metrics
       [-h] [-c CONFIG] [-i INTERVAL] [--user-agent USER_AGENT]
       [-p LISTEN_PORT] [-a LISTEN_ADDRESS]

options:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        The configuration file. (default: ecommerce-
                        exporter.yml)
  -i INTERVAL, --interval INTERVAL
                        The target scrape interval, in minutes. (default: 15)
  --user-agent USER_AGENT
                        The user-agent to spoof. (default: Mozilla/5.0 (X11;
                        Linux x86_64; rv:106.0) Gecko/20100101 Firefox/106.0)
  -p LISTEN_PORT, --listen-port LISTEN_PORT
                        The listen port for the http server. (default: 8000)
  -a LISTEN_ADDRESS, --listen-address LISTEN_ADDRESS
                        The listen address for the http server. (default:
                        0.0.0.0)Configuring the selectorsFinding the correct value for a selector will require some effort. Once you find the correct selector to use, you should be able to use the same one across the whole site.html parserThe general procedure to figure out the selector for a site using an html parser is as follow:Open up the product page in your browser.Right-click the price of the product and select "inspect element" in the drop-down.Take note of theclass, theid, and the type of the element containing the price of the product.Build a CSS selector to select the element with the price of the product you wish to extract.Refer to the documentation on how to build a CSS selector:https://www.w3schools.com/CSS/css_selectors.aspBelow is a table with examples of some CSS selectors that match the html element containing the price of a product. Keep in mind that if the design of the site changes in the future, these selector may stop working.siteselectoramazon.ca.priceToPay .a-offscreen::textcanadacomputer.com.price-show-panel .h2-big strong::textmemoryexpress.com.GrandTotaljson parserThe general procedure to figure out the selector for a site using an json parser is as follow:Open up the development tool of your browser using the F12 key.Open up the product page in your favorite browser.Go to the "network" tab in your development tool and dig through the resources of the page to find the api call that returned the price of the product.Take note of the url of this api call.Use the commandscurl http://url_you_found_in_your_dev_tool | jq 'some_selector'and build a selector to extract the price of the product from the json response.Refer to the documentation of jq on how to build a selector for it:https://stedolan.github.io/jq/manual/#BasicfiltersBelow is a table with examples of some jq selectors that match the json field containing the price of a product. Keep in mind that if the backend/api of the site changes in the future, these selector may stop working. Finding correct url of your product may require some digging in the developper tools of your browser.siteselectorurl examplenewegg.ca.MainItem.UnitCosthttps://www.newegg.ca/product/api/ProductRealtime?ItemNumber=19-118-343&RecommendItem=&BestSellerItemList=9SIAA4YGC82324%2C9SIADGEGMY7603%2C9SIAVH1J0A6685&IsVATPrice=truebestbuy.ca.[] | .salePrice,.regularPricehttps://www.bestbuy.ca/api/offers/v1/products/15778672/offers