Command line tools to lookup the current value of a stock indices via a Google search and output as a single line.
Find a file
2026-02-17 15:00:11 +00:00
google_stocks Fix Google SERP parser after results page markup changes 2026-02-17 14:54:10 +00:00
.gitignore Add gitignore 2023-09-29 12:13:23 +01:00
ftse_all_share Initial commit 2023-09-08 00:07:40 +01:00
LICENSE Add README.md and LICENSE 2023-09-29 12:20:04 +01:00
README.md Update README.md 2026-02-17 15:00:11 +00:00
s_and_p_total_market Fix search for S&P Total Market 2023-11-25 16:06:37 +00:00

Google Stock Index Lookup

Small command-line tools that query Google Search for an index and print a single summary line.

What It Does

  • Runs a Google search for an index (currently FTSE All Share and SPTMI).
  • Parses the finance summary from the results page.
  • Prints one line in this format:
<Index title>: <price> (<percent_change>%)  <timestamp>

Examples:

$ ./ftse_all_share
FTSE All-Share Index: 5650.94 (0.31%)  17 Feb, 14:57 GMT

$ ./s_and_p_total_market
S&P Total Market Index (TMI): 6789.00 (-0.60%)  17 Feb, 09:57 GMT

Requirements

  • Python 3
  • playwright
  • lxml
  • Playwright Chromium browser

Installation

git clone https://git.4angle.com/edward/google-stocks.git
cd google-stocks
python3 -m pip install playwright lxml
python3 -m playwright install chromium

Usage

Run from the repository root:

./ftse_all_share
./s_and_p_total_market

How It Works

  • Entrypoints:
    • ftse_all_share (query: FTSE All Share)
    • s_and_p_total_market (query: SPTMI)
  • Core logic: google_stocks/__init__.py
    • launches headless Chromium via Playwright
    • saves raw SERP HTML to ~/lib/google_stocks/*_serp.html
    • parses the data-attrid="Price" section into structured fields

Local Data and Auth

The tool uses and writes files in your home directory:

  • auth state: ~/lib/auth/google.json
  • captured SERP HTML: ~/lib/google_stocks/

Create directories if needed:

mkdir -p ~/lib/auth ~/lib/google_stocks

Notes

  • Parsing depends on Google SERP markup, which can change.
  • If output breaks, inspect the newest saved SERP in ~/lib/google_stocks/.
  • Values and timestamps are reported in the market context shown by Google (for this project, gl=uk).

Contributing

Issues and PRs are welcome.

License

MIT. See LICENSE.