Wikipedia search

From beita6969/ScienceClaw · View interactive version

Wikipedia search is an AI agent skill from the GitHub repository beita6969/ScienceClaw. Search and fetch structured content from Wikipedia using the MediaWiki API for reliable, encyclopedic information

How to use this skill

Skill file

Wikipedia Search Skill

This skill enables Claude to search and fetch content from Wikipedia using the MediaWiki API. It provides more reliable, structured access to Wikipedia than general web search, with support for summaries, full article content, and multi-language access.

When to Use

Use this skill when you need:

When NOT to Use

Avoid using this skill for:

Usage

The skill is invoked by running the wiki script with a query:

python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "your query" [options]

Options

Common Language Codes

Examples

1. Search for Page Titles

Search for Wikipedia articles matching a term:

python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "quantum computing" --mode search

Output:

{
  "mode": "search",
  "query": "quantum computing",
  "results": [
    {
      "title": "Quantum computing",
      "description": "Study of computers based on quantum phenomena",
      "url": "https://en.wikipedia.org/wiki/Quantum_computing"
    },
    ...
  ],
  "count": 10
}

2. Get a Summary

Get a concise summary of a Wikipedia page:

python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "Python (programming language)" --mode summary

Or with custom sentence count:

python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "Albert Einstein" --mode summary --sentences 3

Output:

{
  "mode": "summary",
  "title": "Albert Einstein",
  "exists": true,
  "url": "https://en.wikipedia.org/wiki/Albert_Einstein",
  "summary": "Albert Einstein was a German-born theoretical physicist...",
  "categories": ["1879 births", "1955 deaths", "German physicists", ...]
}

3. Get Full Article Content

Retrieve the complete article with sections:

python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "Machine learning" --mode full

Output:

{
  "mode": "full",
  "title": "Machine learning",
  "exists": true,
  "url": "https://en.wikipedia.org/wiki/Machine_learning",
  "summary": "Machine learning is a field of study in artificial intelligence...",
  "sections": [
    {
      "title": "History and relationships to other fields",
      "level": 0,
      "text": "..."
    },
    ...
  ],
  "categories": [...],
  "links": ["Artificial intelligence", "Neural network", ...]
}

4. Search in Different Languages

Search or fetch content in other languages:

python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "Paris" --mode summary --lang fr
python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "東京" --mode summary --lang ja

Workflow

When using this skill, follow this workflow:

For Unknown Topics (Search First)

  1. Search for titles — Use --mode search to find relevant articles
  2. Choose the right article — Pick the most relevant title from results
  3. Get summary or full content — Fetch the article with --mode summary or --mode full
  4. Parse JSON output — Extract relevant information from structured data
  5. Cite the source — Include Wikipedia URL when presenting information

For Known Topics (Direct Fetch)

  1. Use exact or close title — Wikipedia is good at matching similar titles
  2. Fetch summary — Use --mode summary for quick facts
  3. Get full content if needed — Use --mode full for comprehensive information
  4. Extract sections — Parse specific sections for focused information

JSON Output Structure

Search Mode
{
  "mode": "search",
  "query": "original query",
  "results": [
    {
      "title": "Page Title",
      "description": "Brief description",
      "url": "https://en.wikipedia.org/wiki/Page_Title"
    }
  ],
  "count": 10
}
Summary Mode
{
  "mode": "summary",
  "title": "Article Title",
  "exists": true,
  "url": "https://en.wikipedia.org/wiki/Article_Title",
  "summary": "Summary text...",
  "categories": ["Category1", "Category2"]
}
Full Mode
{
  "mode": "full",
  "title": "Article Title",
  "exists": true,
  "url": "https://en.wikipedia.org/wiki/Article_Title",
  "summary": "Summary text...",
  "sections": [
    {
      "title": "Section Name",
      "level": 0,
      "text": "Section content..."
    }
  ],
  "categories": ["Category1", "Category2"],
  "links": ["Related Page 1", "Related Page 2"]
}
Error Response
{
  "mode": "summary",
  "title": "Nonexistent Page",
  "exists": false,
  "error": "Page not found"
}

Best Practices

Query Formulation

Mode Selection

Multi-Language Usage

Information Extraction

Attribution Guidelines

When presenting Wikipedia content to users:

Example:

According to Wikipedia, Python is a high-level, general-purpose programming
language that emphasizes code readability with the use of significant indentation.

Source:
- [Python (programming language) - Wikipedia](https://en.wikipedia.org/wiki/Python_(programming_language))

Error Handling

The script handles common errors gracefully:

Page Not Found

If a page doesn't exist:

Network Failures

If the API request fails:

Import Errors

If Wikipedia-API library is missing:

Rate Limiting

Wikipedia's API is generally permissive:

Technical Details

Dependencies

Auto-Installation

The script automatically installs missing dependencies:

subprocess.check_call([
    sys.executable, "-m", "pip", "install",
    "Wikipedia-API", "--break-system-packages", "--quiet"
])

The --break-system-packages flag is needed for externally-managed Python environments (common on modern Linux distributions and macOS with Homebrew Python).

API Details

Exit Codes

Limitations

Wikipedia Constraints

Technical Limitations

Language Support

Troubleshooting

Script Not Executable

If you get "Permission denied" error:

chmod +x ~/.openclaw/skills/wikipedia-search/scripts/wiki.py

Python Not Found

If python3 command doesn't exist, create an alias or use full path to Python interpreter.

Installation Fails in Virtual Environment

If auto-install fails due to venv restrictions, manually install globally:

python3 -m pip install Wikipedia-API --user

Page Not Found for Valid Topic

Non-English Characters Not Displaying

Use Cases and Examples

Research Starting Point

# Start with search
python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "neural networks" --mode search

# Get summary of main article
python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "Artificial neural network" --mode summary

# Get full content for deep dive
python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "Artificial neural network" --mode full

Quick Facts

# Who is someone?
python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "Marie Curie" --mode summary --sentences 2

# What is something?
python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "Blockchain" --mode summary --sentences 3

# Where is something?
python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "Machu Picchu" --mode summary

Historical Information

# Historical events
python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "World War II" --mode full

# Historical figures
python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "Leonardo da Vinci" --mode summary --sentences 10

Scientific Concepts

# Physics
python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "Quantum entanglement" --mode summary

# Biology
python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "DNA" --mode full

# Chemistry
python ~/.openclaw/skills/wikipedia-search/scripts/wiki.py "Periodic table" --mode summary

See Also

Notes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.