Skip to main content

A Python package for crawling Cambridge and OxfordLearners dictionaries

Project description

๐Ÿฆ„ Dictionary Crawler

A Python package for crawling dictionary websites. Currently supports Cambridge Dictionary and Oxford Learners Dictionary.

Installation

pip install dictionary-crawler

Or install from source:

git clone https://github.com/arshinmq/dictionary-crawler.git
cd dictionary-crawler
pip install -e .

Features

  • Async HTTP client for non-blocking requests
  • Parse Cambridge and OxfordLearners Dictionary pages
  • Extract:
    • Headwords and parts of speech
    • Pronunciations (IPA + audio URLs)
    • Definitions with CEFR levels
    • Examples and sources
    • Phrases, idioms, and phrasal verbs
    • Collocations
    • Verb forms
    • Topics and semantic domains (OxfordLearners)
  • Structured Pydantic models for type-safe data access
  • JSON serialization support

Quick Start

import asyncio
from dictionary_crawler import CambridgeCrawler, OxfordLearnersCrawler

async def main():
    # Cambridge Dictionary
    async with CambridgeCrawler() as crawler:
        page = await crawler.crawl("run")
        
        print(f"Search term: {page.search_term}")
        
        for section in page.sections:
            for entry in section.entries:
                print(f"\n{entry.headword} ({entry.part_of_speech})")
                
                if entry.pronunciations:
                    for p in entry.pronunciations:
                        print(f"  [{p.region}] {p.pronunciation}")
                
                for sense in entry.senses:
                    for defn in sense.definitions:
                        print(f"  - {defn.definition}")
                        if defn.examples:
                            for ex in defn.examples:
                                if ex.example:
                                    print(f"    e.g. {ex.example}")
    
    # OxfordLearners Dictionary
    async with OxfordLearnersCrawler() as crawler:
        page = await crawler.crawl("run")
        
        print(f"\nOxfordLearners - Search term: {page.search_term}")
        
        for definition in page.definitions:
            print(f"\n{definition.headword} ({definition.part_of_speech})")
            
            if definition.pronunciations:
                for p in definition.pronunciations:
                    print(f"  [{p.phonetic}]")
            
            for sense in definition.senses:
                print(f"  - {sense.definition}")
                if sense.examples:
                    for ex in sense.examples:
                        print(f"    e.g. {ex.example}")

asyncio.run(main())

API Reference

CambridgeCrawler

The main crawler class for Cambridge Dictionary.

from dictionary_crawler import CambridgeCrawler

async with CambridgeCrawler() as crawler:
    page = await crawler.crawl(word: str) -> CambridgePage

Parameters

  • client (optional): Custom httpx.AsyncClient instance

OxfordLearnersCrawler

The main crawler class for OxfordLearners Dictionary.

from dictionary_crawler import OxfordLearnersCrawler

async with OxfordLearnersCrawler() as crawler:
    page = await crawler.crawl(word: str, direct_call: bool = False) -> OxfordLearnersPage

Parameters

  • client (optional): Custom httpx.AsyncClient instance
  • direct_call (optional): If using the exact endpoint, pass this as true so the package doesn't search the term through OxfordLearners API to find a match. Default is False.

Data Models

OxfordLearnersPage

The root model for OxfordLearners Dictionary data:

Field Type Description
search_term str The word that was searched
definitions list[OxfordLearnersDefinition] List of definitions

OxfordLearnersDefinition

Field Type Description
headword str The word/phrase
part_of_speech str noun, verb, adjective, etc.
pronunciations list[OxfordLearnersPronunciation] Pronunciations
cefr_level CEFRLevel | None CEFR level (A1-C2)
senses list[OxfordLearnersSense] Word senses with definitions
verb_forms list[OxfordLearnersDefinitionVerbForm] | None Verb conjugations
idioms list[OxfordLearnersIdiom] | None Related idioms
phrasal_verbs list[str] | None Related phrasal verbs

OxfordLearnersPronunciation

Field Type Description
phonetic str IPA transcription
pronunciation_url str Audio file URL

OxfordLearnersSense

Field Type Description
semantic_domain str Domain category
definition str The definition text
synonyms list[str] | None Synonyms
topics list[OxfordLearnersSenseTopic] | None Topics with CEFR levels
cefr_level CEFRLevel | None CEFR level (A1-C2)
grammar_labels list[str] | None Grammar labels
labels list[str] | None Usage labels
examples list[OxfordLearnersExample] | None Example sentences
collocations list[OxfordLearnersSenseCollocation] | None Collocations

OxfordLearnersIdiom

Field Type Description
idiom str The idiom text
senses list[OxfordLearnersIdiomSense] Idiom senses

CambridgePage

The root model containing all parsed data:

Field Type Description
search_term str The word that was searched
sections list[CambridgeSection] Dictionary sections (British, American, Business)
examples list[CambridgeExample] | None Example sentences
collocations list[CambridgeCollocation] | None Collocations

CambridgeSection

Field Type Description
type CambridgeSectionType British, American, or Business
entries list[CambridgeEntry] Dictionary entries

CambridgeEntry

Field Type Description
headword str The word/phrase
part_of_speech str noun, verb, adjective, etc.
pronunciations list[CambridgePronunciation] | None Pronunciations
senses list[CambridgeSense] Word senses with definitions
phrases list[CambridgeSectionPhrase] | None Related phrases
idioms list[str] | None Related idioms
phrasal_verbs list[str] | None Related phrasal verbs
verb_forms list[CambridgeVerbForm] | None Verb conjugations

CambridgePronunciation

Field Type Description
pronunciation str IPA transcription
audio_urls list[str] Audio file URLs
region str e.g., "UK", "US"

CambridgeSense

Field Type Description
cefr CEFRLevel | None CEFR level (A1-C2)
definitions list[CambridgeDefinition] Definitions

CambridgeDefinition

Field Type Description
definition str The definition text
examples list[CambridgeDefinitionExample] | None Example sentences
image_urls list[str] | None Illustration URLs

CEFRLevel

Enum with values: A1, A2, B1, B2, C1, C2

Exceptions

Exception Description
DictionaryException Base exception
DictionaryFetchException HTTP request failed
DictionaryWordNotFoundException Word not in dictionary
DictionaryParseException Failed to parse page
CambridgeException Cambridge-specific base
CambridgeFetchException Cambridge fetch error
CambridgeWordNotFoundException Word not in Cambridge
CambridgeParseException Cambridge parse error
OxfordLearnersException OxfordLearners-specific base
OxfordLearnersFetchException OxfordLearners fetch error
OxfordLearnersWordNotFoundException Word not in OxfordLearners
OxfordLearnersParseException OxfordLearners parse error
OxfordLearnersUnexpectedContent Unexpected OxfordLearners page content

JSON Export

Models can be serialized to JSON:

page = await crawler.crawl("example")
json_data = page.model_dump_json(indent=2, ensure_ascii=False)
print(json_data)

Development

Setup

python -m venv venv
source venv/bin/activate
pip install -e ".[dev]"

Running Tests

pytest

Project Structure

dictionary-crawler/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ dictionary_crawler/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ base.py          # BaseCrawler ABC
โ”‚       โ”œโ”€โ”€ http.py          # HTTP client setup
โ”‚       โ”œโ”€โ”€ utils.py         # URL utilities
โ”‚       โ”œโ”€โ”€ exceptions.py    # Custom exceptions
โ”‚       โ”œโ”€โ”€ crawlers/
โ”‚       โ”‚   โ”œโ”€โ”€ cambridge.py # Cambridge parser
โ”‚       โ”‚   โ””โ”€โ”€ oxford_learners.py    # OxfordLearners parser
โ”‚       โ””โ”€โ”€ models/
โ”‚           โ”œโ”€โ”€ common.py    # Shared models (CEFRLevel)
โ”‚           โ”œโ”€โ”€ cambridge.py # Cambridge data models
โ”‚           โ””โ”€โ”€ oxford_learners.py    # OxfordLearners data models
โ””โ”€โ”€ tests/ # Will add soon

Roadmap (Future)

  • Support for additional dictionaries (Merriam-Webster, Collins, etc.)
  • Multi-language support (Spanish, French, German, etc.)
  • Add more test coverage for OxfordLearners support

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dictionary_crawler-0.1.0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dictionary_crawler-0.1.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file dictionary_crawler-0.1.0.tar.gz.

File metadata

  • Download URL: dictionary_crawler-0.1.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for dictionary_crawler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 07319be44cc95145f98420af50adb15de26cb7a519ef7313d54e9dbdf589d0d0
MD5 9b35abd2f954328d46c35626d86088f7
BLAKE2b-256 660c71aa23cf18388655906c2ca4759f7dd3f865cba379553327fac1afc3495a

See more details on using hashes here.

File details

Details for the file dictionary_crawler-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dictionary_crawler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e09d2da603ba29b4d5753da6f243777cca282d398df6640ec69ff4dc4e522545
MD5 5f47ba5fa85815c2940607172ae875f7
BLAKE2b-256 2296e172b4e2ecbb2e51d01b9ba4529e46c0dba0e8d7c9cca92f00d9b0899116

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page