A simple Python program that fetches and displays the first paragraph of a random Wikipedia article using the Wikipedia API.
- Fetches random Wikipedia articles
- Displays the article title and first paragraph
- Provides a link to read the full article
- Interactive mode - fetch multiple articles in one session
- Clean, formatted output
- Error handling for network issues
- Python 3.6+
requestslibrary
- Install the required package:
pip install requestsRun the program:
python main.pyThe program will:
- Fetch a random Wikipedia article
- Display the title and first paragraph
- Show a link to the full article
- Ask if you want to fetch another random article
🌐 Fetching a random Wikipedia article...
======================================================================
📖 RANDOM WIKIPEDIA ARTICLE
======================================================================
🔖 Title: Python (programming language)
📝 First Paragraph:
Python is a high-level, interpreted, general-purpose programming language...
🔗 Read more: https://en.wikipedia.org/wiki/Python_(programming_language)
======================================================================
Would you like another random article? (y/n):
The program uses the Wikipedia REST API endpoint:
https://en.wikipedia.org/api/rest_v1/page/random/summary
This endpoint returns a random article summary, which includes:
- Article title
- First paragraph (extract)
- URL to the full article
- Other metadata
Wikipedia API Documentation: https://en.wikipedia.org/api/rest_v1/
Feel free to fork this project and submit pull requests with improvements!
This project is open source and available for educational purposes.