Web Crawler (Python)

A focused Python crawler with a resumable frontier and trap-aware URL filtering.

Concept illustration of a crawler frontier, link discovery, saved progress, and URL filtering
Concept illustration of a resumable crawl frontier and URL filtering.

Crawl the useful pages, and know what was visited

I worked with a teammate on a Python web crawler for the UCI ICS static corpus. The assignment used a local archive rather than unrestricted live requests, giving us a repeatable setting for examining extraction, URL filtering, and crawl coverage.

My contributions included the crawl loop, absolute-link extraction, trap-aware validation, and analytics for subdomains, page lengths, and term frequencies.


The frontier is part of the system

The crawler keeps pending URLs in a queue and uses a membership set to avoid repeated additions. It saves frontier state and counters to disk so a crawl can resume. An initial run begins from http://www.ics.uci.edu/ within the supplied corpus.

The corpus module maps a URL to its hashed archive filename and decodes the CBOR response. The main loop then extracts candidate links, validates them, and adds eligible URLs back to the frontier.


We used lxml to resolve relative references into absolute URLs. The validator applies protocol and hostname checks, removes fragments, screens non-HTML assets, and rejects suspicious patterns such as repetitive paths, excessive depth, session identifiers, and large query strings.

These are heuristics with tradeoffs. A filter can avoid an unproductive sequence while also excluding a legitimate page. Making the rules explicit was more useful than assuming every rejected URL was necessarily a trap.


Record what the crawl did

The analytics output includes subdomain coverage, the page with the most outlinks, the longest page by extracted word count, and frequent words after stop-word removal. We used BeautifulSoup for text extraction and NLTK stop words for the frequency analysis.

The crawler also records visited URLs and rejected trap candidates in analytics.txt. That makes coverage and filtering behavior available for inspection after the run.


Running the course project

python3 main.py /path/to/spacetime_crawler_data

The supplied static corpus and Python dependencies are required. Clearing the saved frontier starts a fresh crawl.


What I learned

A crawler is a feedback loop: each fetched page can expand the work it still needs to do. This project made URL identity, filtering, and resumable progress feel as important as HTML parsing. It also showed why a final page count is insufficient without knowing how the crawler reached it.