A Python script that scrapes your Instacart order history and saves the data in a JSON file.
The data scraped includes:
- Order date
- Number of unique items
- Order total
- Whether the order was cancelled
- The delivery photo URL (if any)
- The list of items, where the data for each item includes:
- Item name
- Item unit price
- Item unit description (usually weight if applicable)
- Item unit quantity
- Ensure Python dependencies are installed:
pip install -r requirements.txt
- Ensure you have Chromium or Google Chrome installed.
- Ensure you have Chrome Webdriver installed and that it is compatible with the version of Chromium/Chrome you have.
- On Linux, you can run
installChromeDriver.sh
to automatically install/update ChromeDriver in/usr/local/bin
,
- On Linux, you can run
- Optionally, create a
.env
file with your Instacart login email defined asINSTACART_EMAIL
(or ensure that environment variable is present in some other way).- You can skip this and enter the email manually when the script starts.
- Note that even with this variables defined, you will still need to complete the login manually.
- Run the script:
python main.py
- You can use the
--after
argument to only include orders after a certain date/time (format is%Y-%m-%d %H:%M
). - The output is printed to the terminal; if you would like to also save it to a file, use the
--file
argument with a valid file path.- If specified file already exists, it is assumed to be a JSON previously generated by this script for the same Instacart account. In this case, only orders newer than the last order from the existing file are scraped, and the output is a merged file containing all orders. You cannot use the
--after
argument in this case.
- If specified file already exists, it is assumed to be a JSON previously generated by this script for the same Instacart account. In this case, only orders newer than the last order from the existing file are scraped, and the output is a merged file containing all orders. You cannot use the
- You can use the
- You can use the Node.js script
downloadImages.js
with a JSON file generated bymain.py
to download all delivery photos and product thumbnails linked in that file. - You can use
backup.sh
to runmain.py
andinstallImages.js
in a way that is ideal for periodic backups to a dedicated directory (including auto-copying delivery photos to another directory and running another script on them). - You can run
analyze.py
with the path to a JSON generated frommain.py
to generate a CSV that lists all unique items with their average units purchased per month, average units purchased per order, and price fluctuation history.- You can use the
--select
argument to get that info for a specific item only on the terminal. analyze.py
also accepts the--after
date argument.
- You can use the