Awesome
Detik News Search Unofficial API
This script can search and return list of news result
Features
- Search for news articles by query
- Retrieve detailed article content
- Limit the number of search results
Prerequisites
- Python 3.x
- Pip (Python package installer)
- Virtual environment (optional but recommended)
Installation
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Create and activate a virtual environment (optional):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install the required packages:
pip install -r requirements.txt
Make sure you have a
requirements.txt
file with necessary dependencies. For this project, it might include:Flask requests beautifulsoup4
Configuration
Ensure that your script
file contains the DetikNewsApi
class and is correctly implemented. The Flask app in main.py
uses this class for making API requests.
Usage
-
Run the Flask application:
python main.py
-
Access the API endpoints:
-
Search for news articles:
- For details and limit:
GET /search?q=<query>&detail=<true|false>&limit=<number>
- Without details and limit:
GET /search?q=<query>
- For details and limit:
-
Parameters:
q
: The search query (required).detail
: Whether to include the full article body in the response (true
orfalse
). Defaults tofalse
.limit
: The maximum number of results to return. Defaults toNone
.
-
Example Request:
GET /search?q=makan%20siang%20gratis&detail=true&limit=5
-
Example Response:
{ "status": 200, "data": [ { "judul": "Example Title", "link": "https://news.detik.com/example", "gambar": "https://example.com/image.jpg", "body": "Full article body...", "waktu": "2024-08-04T12:34:56" } // Additional articles... ], "length": 5 }
-