Skip to content

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.

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:

Terminal window
git clone https://github.com/lexiforest/brimp.git
cd brimp
python3 docs/fixtures/server.py

On 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.

Pick one interface. All three use the same runtime.

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"))

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:

200
Hello from JavaScript
Terminal window
brimp fetch http://127.0.0.1:8765/ --eval 'document.querySelector("h1").textContent'

The CLI writes the evaluated value as JSON: "Hello from JavaScript".

Terminal window
brimp fetch http://127.0.0.1:8765/ --format markdown

The 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.

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.

Continue with Python, Node, or CLI tutorials.