JavaScript-rendered pages with Lightpanda
File: lightpanda.lisp
Some pages show little content until JavaScript runs. Lightpanda is a small headless browser built for this case; here Lisp runs it as a subprocess.
The code
1 ;; sbcl --script lightpanda.lisp (needs the lightpanda binary on PATH)
2 (require :asdf)
3
4 (defun lightpanda (url &optional (dump "html"))
5 "DUMP is a text format: html, markdown, semantic_tree,
6 semantic_tree_text, or structured_data."
7 (uiop:run-program
8 (list "lightpanda" "fetch" "--dump" dump
9 "--log-level" "warn" url)
10 :output :string))
11
12 (defun links (html)
13 (loop for i = (search "href=\"" html)
14 then (search "href=\"" html :start2 end)
15 for end = (and i (position #\" html :start (+ i 6)))
16 while end collect (subseq html (+ i 6) end)))
17
18 (print (lightpanda "https://markwatson.com/" "markdown"))
19 (print (links (lightpanda "https://markwatson.com/")))
How it works
lightpanda fetchrenders the page (JavaScript included) and dumps it as text: rawhtml, amarkdownconversion, thesemantic_treevariants that expose the page’s structure, orstructured_data(JSON-LD, OpenGraph, and meta tags as JSON). Lightpanda can also dumppdfandpng, but those are binary and this function returns a string, so it sticks to the text formats.--log-level warnkeeps diagnostics off standard output so the return value stays clean.linksis a simple string scan, not an HTML parser:searchfinds eachhref="marker andpositionfinds the closing quote. That works for the tidy HTML a renderer emits; for arbitrary HTML, use the parser in the web-scraping chapter.
Running it
Install Lightpanda so the lightpanda binary is on your PATH, then:
1 $ sbcl --script lightpanda.lisp
The first print shows the home page as a Markdown string (headings, links, and text without HTML markup). Actual output, abridged:
1 "[Mark Watson ](https://markwatson.com/#)
2 - [Systems Thinking](https://markwatson.com/#systems)
3 - [Books](https://markwatson.com/#books)
4 - [Connect](https://markwatson.com/#connect)
5 - [Free Mentoring](https://markwatson.com/#mentoring)
6 - [Flagstaff Arizona](https://markwatson.com/flagstaff.html)
7 - [Blogspot](https://mark-watson.blogspot.com/)
8 - [Substack](https://marklwatson.substack.com/)
9 - [GitHub](https://github.com/mark-watson)
10 - [Leanpub](https://leanpub.com/u/markwatson)
11
12 # Mark Watson
13
14 ****Systems Thinker & Generalist AI Expert****
15
16 Synthesizing complex technologies across 40\\+ years of computing.
17 I approach artificial intelligence through a systems\\-thinking lens
18 by bridging modern LLMs, neural networks, knowledge graphs, and
19 symbolic reasoning with large\\-scale distributed architectures.
20
21 Self\\-funded open source researcher and author, with engineering
22 and advisory experience for organizations including **Google**,
23 **Mind AI**, **Capital One**, **Disney**, **SAIC/Leidos**, **DARPA**,
24 **Babylist**, **Olive AI**, and **CompassLabs**.
25 ...
26 "
The second prints a list of the page’s href strings. Actual output, abridged:
1 ("/index.css" "#" "#systems" "#books" "#connect" "#mentoring"
2 "/flagstaff.html" "https://mark-watson.blogspot.com/"
3 "https://marklwatson.substack.com" "https://github.com/mark-watson"
4 "https://leanpub.com/u/markwatson" "#systems" "#books" "#connect"
5 "https://leanpub.com/pythonai/read" "https://leanpub.com/pythonai"
6 "https://leanpub.com/lovinglisp/read" "https://leanpub.com/lovinglisp"
7 "https://leanpub.com/clojureai/read" "https://leanpub.com/clojureai"
8 "https://leanpub.com/haskell-cookbook/read"
9 "https://leanpub.com/haskell-cookbook/" "https://leanpub.com/javaai/read"
10 "https://leanpub.com/javaai" "https://leanpub.com/hy-lisp-python/read"
11 "https://leanpub.com/hy-lisp-python"
12 ...
13 "https://leanpub.com/u/markwatson" "/flagstaff.html" "/privacy.html")
Using it
The markdown dump suits AI pipelines: it turns a JavaScript-heavy page into compact text you can pass to a model from the Gemini or Ollama chapters. For interactive work (clicking links, filling in forms, waiting for content), run lightpanda serve, which exposes the Chrome DevTools Protocol over a WebSocket, and control it from a CDP client. This chapter covers the simple case: one subprocess call per page.