# Crawl a Website and Export Every Page URL and Title to JSON

> Give the crawler one start URL; it follows every internal link in a real Chromium browser and writes url, title and a content snippet per page to results.json.

URL: https://thuyavan.netlify.app/scripts/website-link-crawler
Updated: 2026-10-07

## Problem
Collecting every page of a help centre or documentation site by hand means endless clicking and copy-pasting.

## Solution
A PlaywrightCrawler starts at one URL, calls enqueue_links() on every page to follow same-site links, and stores URL, title and the first 100 characters of HTML in a dataset.

## Result
A results.json inventory of the whole site plus a printed page count.

## Input
- One start URL in crawler.run([...])

## Output
- results.json - one record per crawled page

## Optional output
- Crawlee storage/ folder with datasets and request queues
- Page count printed to the console

## System flow
Start URL (crawler.run([...])) -> Playwright page (Chromium renders JS) -> enqueue_links() (Follow same-site links) -> push_data() (url · title · snippet) -> results.json (export_data())

## How it works
- **Real browser:** Playwright renders JavaScript-heavy pages that plain HTTP scrapers miss.
- **Automatic link following:** enqueue_links() queues new same-domain links, so the crawl widens by itself.
- **Simple dataset export:** Everything collected is exported to results.json with one call.
- **Adjustable limits:** Set max_requests_per_crawl to cap the crawl, or switch headless on.

## Configuration
- `headless`: False shows the browser window; True runs invisibly.
- `browser_type`: Browser engine, 'chromium' by default.
- `max_requests_per_crawl`: Optional cap to avoid huge crawls (commented out).

## How to run
Install:

    pip install -r requirements.txt
Install the browser:

    playwright install chromium
Run:

    python link_crawler.py

## Impact
- A full page inventory in minutes.
- Works on JavaScript-rendered sites.
- Tiny script that is easy to extend.

## FAQ
**How do I crawl all links on a website with Python?**
Use Crawlee PlaywrightCrawler and call enqueue_links() in the request handler; the crawler follows same-site links automatically.

**Can I limit how many pages it crawls?**
Yes. Uncomment max_requests_per_crawl.

**Is it polite to crawl any website?**
Crawl only sites you are allowed to, respect robots.txt and rate limits.

