Skip to content

Commit d33ef02

Browse files
committed
feat(cli): add LLM-friendly output
1 parent c0c98b8 commit d33ef02

10 files changed

Lines changed: 445 additions & 202 deletions

File tree

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,26 @@ flags, but pages that need WebGL or canvas export may not work correctly.
362362

363363
## CLI
364364

365+
`webskrap fetch` always runs headless Patchright stealth mode. Install the
366+
stealth extra before using it. `webskrap doctor` verifies this CLI setup.
367+
368+
```bash
369+
pip install "webskrap[stealth]"
370+
patchright install chromium
371+
```
372+
365373
```bash
366374
webskrap profiles
375+
webskrap profiles --format json
367376
webskrap doctor
377+
webskrap doctor --format json
368378
webskrap fetch https://example.com --profile desktop-chrome
369-
webskrap fetch https://example.com --headed --screenshot example.png
370-
webskrap fetch https://example.com --driver patchright --channel chrome --headed \
371-
--user-data-dir .webskrap/patchright-profile
379+
webskrap fetch https://example.com --format json --max-chars 12000
380+
webskrap fetch https://example.com --stdout --text-only
381+
webskrap fetch https://example.com --screenshot example.png
382+
webskrap fetch https://example.com --channel chrome \
383+
--user-data-dir .webskrap/headless-profile
372384
webskrap fetch https://amiunique.org/fr/fingerprint \
373-
--driver patchright \
374385
--channel chrome \
375386
--mask-headless-user-agent \
376387
--patchright-context-profile \

SKILL.md

Lines changed: 68 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
---
22
name: webskrap
3-
description: Use when writing, debugging, documenting, or reviewing Python scraping and browser automation code with WebSkrap. Covers async fetches, persistent sessions, Playwright/Patchright drivers, browser profiles, resource policies, screenshots, proxies, timeouts, CLI usage, MCP server usage, and safe examples that avoid CAPTCHA solving, login-wall bypassing, credential bypassing, or access-control circumvention.
3+
description: Use when writing, debugging, documenting, or reviewing Python scraping and browser automation code with WebSkrap. Covers async fetches, persistent sessions, Playwright/Patchright drivers, browser profiles, resource policies, screenshots, proxies, timeouts, LLM-friendly CLI output, MCP server usage, and safe examples that avoid CAPTCHA solving, login-wall bypassing, credential bypassing, or access-control circumvention.
44
---
55

66
# WebSkrap
77

8-
WebSkrap is an async-first Python scraping framework built on Playwright for realistic browser sessions, coherent profiles, resource controls, and structured fetch results.
8+
WebSkrap is an async-first Python scraping package built on Playwright, with
9+
Patchright support for stealth-oriented browser sessions.
910

10-
## Start Here
11+
## Read First
1112

12-
Before giving detailed guidance, check the local docs when available:
13+
Prefer current repo sources over memory:
1314

14-
- `docs/getting-started/quickstart.md`: first examples for fetches, sessions, clicks, screenshots, and CLI.
15-
- `docs/user-guide/client.md`: `WebSkrapClient`, one-shot fetches, timeouts, screenshots, and `FetchResult`.
16-
- `docs/user-guide/sessions.md`: persistent sessions, headed debugging, page workflows, and human-like clicks.
17-
- `docs/user-guide/profiles.md`: built-in and custom browser profiles.
18-
- `docs/user-guide/resource-policy.md`: resource blocking presets.
19-
- `docs/user-guide/stealth.md`: Patchright, headless behavior, WebRTC policy, and fingerprint-surface controls.
20-
- `docs/user-guide/cli.md`: `webskrap` command examples.
21-
- `docs/user-guide/mcp.md`: optional MCP server setup and tool arguments.
22-
- `docs/api-reference.md`: generated public API reference.
15+
- `README.md`: user-facing examples and install notes.
16+
- `src/webskrap/client.py`: `WebSkrapClient`, sessions, fetch flow, screenshots.
17+
- `src/webskrap/models.py`: public Pydantic models, `SessionConfig`, result shape.
18+
- `src/webskrap/profiles.py`: bundled browser profiles.
19+
- `src/webskrap/cli.py`: current `webskrap` command behavior.
20+
- `src/webskrap/mcp_server.py`: MCP tools and argument shape.
21+
- `tests/`: behavior contracts when changing parsing, state, CLI, stealth, or safety.
2322

2423
## Guardrails
2524

26-
- Do not add CAPTCHA solving, login-wall bypassing, credential bypassing, or access-control circumvention.
27-
- Keep examples limited to public pages, local servers, or targets the user is allowed to access.
28-
- Do not commit cookies, storage state, proxy credentials, or persistent browser data such as `.webskrap/`.
29-
- Prefer typed public APIs exported by `webskrap`; avoid reaching into private helpers except in tests.
30-
- Use `async with WebSkrapClient()` unless you are explicitly demonstrating manual `start()` / `close()`.
25+
- Do not add CAPTCHA solving, login-wall bypassing, credential bypassing, or
26+
access-control circumvention.
27+
- Use public pages, local test servers, or targets the user is allowed to access.
28+
- Do not commit cookies, storage state, proxy credentials, or persistent browser
29+
data such as `.webskrap/`.
30+
- Prefer public exports from `webskrap`; use private helpers only in tests.
31+
- Keep changes small and typed. Add focused tests for parsing, state transitions,
32+
CLI output, and tool-safety behavior.
3133

32-
## Core Workflow
34+
## Python API
3335

34-
Install WebSkrap and the Playwright browser before running examples:
36+
Install normal API/browser support:
3537

3638
```bash
3739
pip install webskrap
3840
python -m playwright install chromium
3941
```
4042

41-
Use `WebSkrapClient` as an async context manager. Use `client.fetch()` for one-shot page fetches. Use `client.session()` when browser state, cookies, local storage, human-like clicks, or a headed browser should persist across actions.
42-
43-
## Common Patterns
44-
45-
One-shot fetch:
43+
Use `WebSkrapClient` as an async context manager. Use `client.fetch()` for a
44+
one-shot fetch. Use `client.session()` when cookies, storage, manual page work,
45+
human-like clicks, or headed debugging should persist.
4646

4747
```python
4848
import asyncio
@@ -60,123 +60,35 @@ async def main() -> None:
6060
asyncio.run(main())
6161
```
6262

63-
Fetch with a screenshot and custom navigation wait:
64-
65-
```python
66-
result = await client.fetch(
67-
"https://example.com",
68-
wait_until="load",
69-
screenshot="example.png",
70-
timeout_ms=60_000,
71-
)
72-
print(result.screenshot_path)
73-
```
74-
75-
Persistent session with storage between runs:
76-
77-
```python
78-
import asyncio
79-
from pathlib import Path
80-
81-
from webskrap import SessionConfig, WebSkrapClient
82-
83-
84-
async def main() -> None:
85-
config = SessionConfig(user_data_dir=Path(".webskrap/session"), headless=True)
86-
87-
async with WebSkrapClient() as client:
88-
session = await client.session("default", config=config)
89-
first = await session.fetch("https://example.com")
90-
second = await session.fetch("https://example.com/account")
91-
print(first.status, second.status)
92-
93-
94-
asyncio.run(main())
95-
```
96-
97-
Manual page workflow:
98-
99-
```python
100-
async with WebSkrapClient() as client:
101-
session = await client.session("debug", config=SessionConfig(headless=False))
102-
page = await session.context.new_page()
103-
await page.goto("https://example.com", wait_until="domcontentloaded")
104-
await session.human_click(page, "a")
105-
```
106-
107-
Custom profile:
108-
109-
```python
110-
from webskrap import BrowserProfile, Viewport
111-
112-
profile = BrowserProfile(
113-
name="fr-desktop",
114-
viewport=Viewport(width=1440, height=900),
115-
screen=Viewport(width=1440, height=900),
116-
locale="fr-FR",
117-
timezone_id="Europe/Paris",
118-
navigator_languages=["fr-FR", "fr", "en-US", "en"],
119-
)
120-
```
121-
122-
Resource policy:
123-
124-
```python
125-
from webskrap import ResourcePolicy, SessionConfig
126-
127-
config = SessionConfig(resource_policy=ResourcePolicy.LITE)
128-
```
129-
130-
Proxy and timeout configuration:
131-
132-
```python
133-
from webskrap import ProxyConfig, ResourcePolicy, SessionConfig
134-
135-
config = SessionConfig(
136-
proxy=ProxyConfig(server="http://127.0.0.1:8080"),
137-
resource_policy=ResourcePolicy.LITE,
138-
navigation_timeout_ms=90_000,
139-
default_timeout_ms=90_000,
140-
)
141-
```
142-
143-
Patchright headed stealth path:
63+
The Python API defaults to Playwright. For Patchright, opt in through
64+
`SessionConfig`:
14465

14566
```bash
14667
pip install "webskrap[stealth]"
14768
patchright install chromium
14869
```
14970

15071
```python
72+
from pathlib import Path
73+
15174
from webskrap import SessionConfig
15275

15376
config = SessionConfig(
15477
driver="patchright",
15578
channel="chrome",
156-
headless=False,
79+
headless=True,
80+
user_data_dir=Path(".webskrap/headless-profile"),
15781
)
15882
```
15983

160-
Use Patchright for CDP-aware detection surfaces. It uses a persistent context for full stealth; if `user_data_dir` is omitted, WebSkrap creates a temporary persistent profile. WebSkrap does not inject JavaScript stealth patches, so let the real browser fingerprint show through.
161-
162-
Headless Patchright is best-effort. Prefer real Chrome, a stable `user_data_dir`, a coherent virtual screen, and the browser-level user-agent mask only when the user asks for headless stealth:
84+
Headed Patchright is strongest for strict detection surfaces:
16385

16486
```python
165-
from pathlib import Path
166-
167-
from webskrap import SessionConfig, Viewport
168-
169-
config = SessionConfig(
170-
driver="patchright",
171-
channel="chrome",
172-
headless=True,
173-
user_data_dir=Path(".webskrap/headless-profile"),
174-
headless_screen=Viewport(width=1366, height=768),
175-
mask_headless_user_agent=True,
176-
)
87+
config = SessionConfig(driver="patchright", channel="chrome", headless=False)
17788
```
17889

179-
For fingerprint-statistics or WebRTC leak-test pages, use native browser controls instead of JavaScript patches:
90+
For fingerprint-statistics or WebRTC leak-test pages, prefer native browser
91+
controls over JavaScript patches:
18092

18193
```python
18294
config = SessionConfig(
@@ -185,44 +97,64 @@ config = SessionConfig(
18597
headless=True,
18698
patchright_context_profile=True,
18799
reduce_fingerprint_surface=True,
100+
mask_headless_user_agent=True,
188101
webrtc_ip_handling_policy="disable_non_proxied_udp",
189102
)
190103
```
191104

192-
These settings do not hide the page's normal remote address and do not normalize unrelated high-entropy surfaces such as fonts, battery, TLS/session metadata, or installed browser features.
105+
## CLI
193106

194-
CLI fetch:
107+
The CLI `fetch` command always uses headless Patchright stealth mode. Install
108+
the stealth extra first; `webskrap doctor` checks this CLI setup.
195109

196110
```bash
111+
pip install "webskrap[stealth]"
112+
patchright install chromium
113+
197114
webskrap doctor
115+
webskrap doctor --format json
198116
webskrap profiles
199-
webskrap fetch https://example.com --profile desktop-chrome --screenshot example.png
200-
webskrap fetch https://example.com --output page.html --resource-policy lite
201-
webskrap fetch https://example.com --driver patchright --channel chrome --headed
117+
webskrap profiles --format json
118+
webskrap fetch https://example.com --profile desktop-chrome
119+
webskrap fetch https://example.com --format json --max-chars 12000
120+
webskrap fetch https://example.com --stdout --text-only
121+
webskrap fetch https://example.com --quiet --output page.html
202122
```
203123

204-
MCP server:
124+
`fetch --format json` prints bounded JSON to stdout using the MCP-compatible
125+
shape: `url`, `final_url`, `status`, `ok`, `title`, `headers`, `text`,
126+
`text_length`, `text_truncated`, and `elapsed_ms`.
127+
128+
Use `--stdout` for raw fetched content, and combine it with `--text-only` for
129+
readable body text.
130+
131+
## MCP
132+
133+
Install MCP support when an MCP client should call WebSkrap directly:
205134

206135
```bash
207136
pip install "webskrap[mcp]"
208137
python -m playwright install chromium
209138
webskrap-mcp
210139
```
211140

212-
Use `stealth_fetch` only after installing both MCP and stealth extras:
141+
MCP tools:
213142

214-
```bash
215-
pip install "webskrap[mcp,stealth]"
216-
patchright install chromium
217-
```
143+
- `fetch`: standard Playwright fetch.
144+
- `stealth_fetch`: Patchright fetch; requires `pip install "webskrap[mcp,stealth]"`
145+
and `patchright install chromium`.
146+
- `doctor`: Playwright/Chromium MCP readiness check.
218147

219148
## Validation
220149

221-
For code changes, run the focused checks relevant to the edit:
150+
For non-trivial changes run:
222151

223152
```bash
224153
pytest -q
225154
ruff check .
155+
python -m build
226156
```
227157

228-
Use `WEBSKRAP_LIVE=1 pytest -q -m live` only for opt-in third-party bot-detection tests. Those tests are slower and may fail when public demos change.
158+
Use `WEBSKRAP_LIVE=1 pytest -q -m live` only when explicitly checking public
159+
third-party bot-detection behavior. Those tests are opt-in and can fail when
160+
external demos change.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "webskrap"
7-
version = "0.5.2"
7+
version = "0.5.3"
88
description = "A Playwright-based Python scraping framework with coherent browser profiles and session controls."
99
readme = "README.md"
1010
requires-python = ">=3.11"

0 commit comments

Comments
 (0)