Skip to main content

Modules

Webgrph

Site structure mapping, crawl, and hierarchy — the engine behind crawl()

3 min read


Webgrph is the site mapping module that powers the discovery phase of client.crawl(). It maps the structure of a website breadth-first, from the root page down to max_depth.

The high-level client.crawl() orchestrator calls Webgrph internally — you don't need to poll or manage crawl IDs yourself. See crawl() for the one-call API.

crawl

webgrph.crawl starts the crawl, waits for it to finish, and returns its pages.

crawl = client.webgrph.crawl(
    "https://example.com",
    max_depth=3,
    max_pages=500,
)
print(crawl.crawl_id, crawl.total_pages, crawl.max_depth_reached)
for p in crawl.pages:
    print(p.url, p.depth, p.title)
const crawl = await client.webgrph.crawl('https://example.com', { maxDepth: 3, maxPages: 500 });
console.log(crawl.crawlId, crawl.totalPages);

Pass session_artifact_id (from fetchyr.authenticate) to crawl behind a login.

start_crawl / get_crawl_status (manage it yourself)

import time

crawl_id = client.webgrph.start_crawl("https://example.com", max_depth=3)
while True:
    status = client.webgrph.get_crawl_status(crawl_id)
    print(status["status"], status["total_pages"])
    if status["status"] in ("completed", "failed", "cancelled"):
        break
    if status["status"] == "held_quota":      # out of data: held, not failed
        print(status["message"])
        break
    time.sleep(3)

page = client.webgrph.get_crawl_pages(crawl_id, limit=500)   # cursor-paginated
all_pages = client.webgrph.crawl_all_pages(crawl_id)          # every page

The status carries crawl_id, status, total_pages (the pages found), max_depth_reached, artifact_id, error, and the outcome fields pages_discovered, pages_fetched, pages_unfetched, is_partial, partial_reason, resumable, error_code and message. A completed crawl with is_partial: true stopped early; one with resumable: true can be continued. A crawl that could not fetch the site ends failed with the reason in error (not an HTTP error). cancel_crawl(crawl_id) stops a running crawl. Pages are kept for 2 hours; see crawl() for the statuses, limits and errors.

crawl_all

for p in client.webgrph.crawl_all("https://example.com", max_depth=3):
    print(p.url, p.depth)

crawl_stream / crawlStream (SSE)

for event in client.webgrph.crawl_stream("https://example.com"):
    print(event.type, event.stage_id, event.sub_status, event.progress_pct)
for await (const event of client.webgrph.crawlStream('https://example.com')) {
  console.log(event.eventType, event.stageId, event.message, event.progressPct);
}

The event name (type in Python, eventType in TypeScript) is pipeline_step, pipeline_error or pipeline_complete; the stream ends after pipeline_complete. To reattach after a dropped connection, pass the last sequence you saw: crawl_events(crawl_id, last_sequence=N) / crawlEvents(crawlId, N). The event fields are listed under SSE streaming.

Page fields

The API's page object (…/crawl/{crawl_id}/pages; limit 1–1000, default 100). By default it leaves out the folders the site tree groups pages under, which were never fetched; include_grouping=true adds them, flagged metadata.is_grouping:

| Field | Type | Description | |-------|------|-------------| | id | string | Node ID | | url | string | Page URL | | parent_url | string or null | The page it was found on | | children_urls | string list | URLs of child pages | | depth | integer | Depth from root | | category | string | Page category from the link classifier, for example content, listing, static, downloadable or blocked_robots; a value outside its list is other (crawl pages) | | classification_confidence | number | Confidence of category | | metadata | object | title, link_text, link_context, is_navigation, is_content, estimated_importance, is_api_node, api_endpoint, record_count, api_data, is_grouping, fetch_status, fetch_error |

The SDKs' page objects carry url, depth, title (from metadata) and children (from children_urls). The API sends no per-page HTTP status, so the SDK's status_code is empty (the Python and TypeScript SDKs remove the attribute in 0.7.0); fetch a page with evadr.fetch for its status.

Next steps

Was this page helpful?