Here’s a battle-tested, end-to-end pattern you can follow. In a nutshell we’ll:
- Read your product-URL list from Google Sheets
- Spin up a headless browser (Selenium/Playwright) to fetch each page’s live price
- Append a timestamped row back into the same sheet
- Schedule the whole thing to run 3×/day (08:00, 13:00, 18:00) via your PC’s Task Scheduler / cron or a cloud scheduler
1. Google Sheets setup
- Create or open your Google Sheet.
- In the sheet (“Products”), list in col A your product URLs and, optionally, col B a human-readable description.
- Share the sheet with a service-account email (we’ll create that below).
2. Create a Google service-account & enable the Sheets API
- Go to the GCP Console → IAM & admin → Service accounts → Create.
- Download its JSON key.
- In GCP API library → enable “Google Sheets API” for your project.
- Share your Sheet (View/Edit) with the service-account’s email.
3. Python script
Install dependencies:
pip install gspread oauth2client selenium webdriver-manager schedule
Save this as price_updater.py:
import time
from datetime import datetime
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
import schedule
# 1) Google Sheets auth
SCOPE = ["https://spreadsheets.google.com/feeds",
"https://www.googleapis.com/auth/drive"]
CREDS = ServiceAccountCredentials.from_json_keyfile_name("service_account.json", SCOPE)
GSHEET = gspread.authorize(CREDS)
SHEET = GSHEET.open("YourSheetName").worksheet("Products")
LOG_SHEET = GSHEET.open("YourSheetName").worksheet("Log") # target for results
# 2) Selenium headless Chrome factory
def make_driver():
chrome_opts = Options()
chrome_opts.add_argument("--headless")
chrome_opts.add_argument("--no-sandbox")
chrome_opts.add_argument("--disable-dev-shm-usage")
return webdriver.Chrome(ChromeDriverManager().install(), options=chrome_opts)
# 3) scraping logic per domain
def fetch_price(driver, url):
driver.get(url)
time.sleep(3) # allow JS to load
if "flipkart.com" in url:
el = driver.find_element_by_css_selector("._30jeq3")
elif "swiggy.com" in url:
el = driver.find_element_by_css_selector(".B_NuCI")
elif "blinkit.com" in url:
el = driver.find_element_by_css_selector(".price")
elif "zepto.com" in url:
el = driver.find_element_by_css_selector(".productPrice")
else:
return "UNKNOWN-DOMAIN"
return el.text.strip()
# 4) Master job
def job():
print(f"Starting run @ {datetime.now()}")
urls = SHEET.col_values(1)[1:] # skip header
cats = SHEET.col_values(2)[1:] # optional names
driver = make_driver()
for idx, url in enumerate(urls):
try:
price = fetch_price(driver, url)
except Exception as e:
price = f"ERROR: {e}"
ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
row = [ts, cats[idx] or "", url, price]
LOG_SHEET.append_row(row)
print("Logged:", row)
driver.quit()
print("Run complete.\n")
# 5) Schedule: 08:00, 13:00, 18:00
schedule_times = ["08:00", "13:00", "18:00"]
for t in schedule_times:
schedule.every().day.at(t).do(job)
print("Scheduler started. Waiting for next run…")
while True:
schedule.run_pending()
time.sleep(30)
● Rename your sheet’s tabs to “Products” (URL list) and “Log” (where prices go).
● The script authenticates, reads URLs, headlessly visits each, extracts the price via a CSS selector (tweak if the site changes), then appends a timestamped row.
● Tweak the CSS selectors to match the current DOM of Blinkit/Swiggy/Zepto/Flipkart as needed.
4. Running & Scheduling
A) On your PC (Windows)
- Save
service_account.json & price_updater.py in one folder.
- Open Task Scheduler → Create Basic Task → “Daily”, repeat every 1 day, start at e.g. 07:55 AM, Advanced → repeat task every 6 hours, for 12 hours (so it fires at ~08:00, ~14:00, ~20:00).
- Action → “Start a program” →
python C:\path\to\price_updater.py
B) On Linux / macOS
– Simply run nohup python3 price_updater.py & in a screen/tmux, or add a cron entry:
0 8,13,18 * * * /usr/bin/python3 /home/you/price_updater.py
5. Production Tips
• Use rotating proxies or respect robots.txt—these sites may block heavy scraping.
• Increase time.sleep() if pages are slow.
• Log failures to a separate tab.
• If you outgrow a PC, move to a small VPS or Google Cloud Run + Cloud Scheduler.
—---
And that’s it! Once configured, your Python “watchdog” will tick off every morning, afternoon and evening, fetch live prices for each link, and stamp them neatly into your Google Sheet. 🚀