Quick start
In this tutorial, a page starts with Waiting for JavaScript and changes its heading to Hello from JavaScript. You’ll read the changed heading through Brimp, then extract the article as Markdown.
1. Start the example site
Section titled “1. Start the example site”Install Brimp for your chosen interface. The examples below use a small local website so their output is reproducible. The package does not include that website; get it from the repository in a separate terminal:
git clone https://github.com/lexiforest/brimp.gitcd brimppython3 docs/fixtures/server.pyOn Windows, use python if python3 is not available. The server uses only the
Python standard library; it does not need Brimp installed.
Keep it running at http://127.0.0.1:8765. The examples use this local site so
that you can reproduce the results without relying on a public website.
2. Read the live DOM
Section titled “2. Read the live DOM”Pick one interface. All three use the same runtime.
Python
Section titled “Python”In the environment where you installed Brimp, save this as first_page.py,
then run python first_page.py:
import brimp
with brimp.Session() as session: page = session.get("http://127.0.0.1:8765/") print(page.status_code) print(page.evaluate("document.querySelector('h1').textContent"))Node.js
Section titled “Node.js”In the application directory where you installed @brimp/brimp, save this as
first-page.mjs, then run node first-page.mjs:
import { createSession } from '@brimp/brimp';
const session = await createSession();try { const page = await session.get('http://127.0.0.1:8765/'); console.log(page.statusCode); console.log(await page.evaluate("document.querySelector('h1').textContent"));} finally { await session.close();}Both programs print:
200Hello from JavaScriptbrimp fetch http://127.0.0.1:8765/ --eval 'document.querySelector("h1").textContent'The CLI writes the evaluated value as JSON: "Hello from JavaScript".
3. Extract the article
Section titled “3. Extract the article”brimp fetch http://127.0.0.1:8765/ --format markdownThe output contains Hello from JavaScript and the article text. The CLI loads its article-extraction plugin for Markdown and extraction JSON output. To extract from Python or Node.js, follow the extraction tutorial.
What you just used
Section titled “What you just used”| Object | Job |
|---|---|
| Session | Owns pages, shared cookies, request defaults and plugins |
| Page | Holds the current response and live DOM; evaluates browser JavaScript |
page.text |
Original response text, before DOM changes |
page.html() |
Current serialized DOM; await it in Node |
Closing a session closes its pages. Python timeouts use seconds; Node uses milliseconds. Brimp executes scripts and DOM operations without painting a screenshot or calculating layout.