hirunews-scrap
v2.0.1
Published
An unofficial Node.js package for scraping latest news from Hiru News (hirunews.lk). Supports breaking news, trending, sports, entertainment and more.
Maintainers
Readme
Installation
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
yarn add hirunews-scrapor
npm i hirunews-scrap🎈 Usage
const Hiru = require('hirunews-scrap');
const api = new Hiru();
const apiWithOptions = new Hiru({
proxy: 'https://example.workers.dev',
userAgent: 'MyScraper/1.0 (+https://example.com)',
headers: { 'Accept-Language': 'en-US' },
timeout: 15000,
rateLimit: 1,
cache: { ttl: 300000, maxSize: 200 }
});TypeScript (typed) example
import Hiru = require('hirunews-scrap');
const api = new Hiru({ userAgent: 'MyBot/1.0' });
async function main() {
const res = await api.BreakingNews();
console.log(res.results.title);
}
main();Options
All options available in utils/options.js can be passed to new Hiru({...}). Key items:
timeout(ms) — request timeoutmaxRetries— retry attemptsretryDelay— base delay between retries (ms)headers— default HTTP headers (deep-merged)userAgent/ua— shorthand aliases forheaders['User-Agent']followRedirects— follow 3xx redirectsvalidateStatus— function to validate HTTP status codesrateLimit— requests per secondproxy— string (e.g.http://user:pass@host:8080) or axios-style objectrotateUserAgent— enable UA rotationcache—trueor{ ttl, maxSize }
Notes:
headersfrom your options are deep-merged with library defaults.proxyaccepts a URL string (auto-parsed) or an object with{ host, port, protocol, auth }.- Options passed to
new Hiru({...})are applied when the instance is constructed; create a new instance to change defaults at runtime.
Error handling
Library errors are structured and include name, code, message and optional meta.
Check err.code or err.name when catching errors:
try {
await api.MainNews();
} catch (err) {
console.error(err.code || err.name, err.message);
if (err.meta) console.debug('meta:', err.meta);
}API
Get Latest Breaking News
const News = await api.BreakingNews();
console.log(News);{
"code": 200,
"code_creator": {
"name": "Omindu_Dissanayaka",
"github": "@OminduDissanayaka",
"website": "https://www.omindu.dev"
},
"results": {
"title": "රාජිතට එරෙහි නඩුවේ තීන්දුව ප්රකාශ කිරීම නොවැම්බර් 29 වැනිදා",
"news": "2019 වසරේ පැවැති ජනාධිපතිවරණ සමයේ...",
"thumb": "https://cdn.hirunews.lk/Data/News_Images/202410/1729749426_3059902_hirunews.jpg",
"date": "Thursday, 24 October 2024 - 11:27",
"newsURL": "https://www.hirunews.lk/385906/රාජිතට-එරෙහි-නඩුවේ-තීන්දුව-ප්රකාශ-කිරීම-නොවැම්බර්-29-වැනිදා"
}
}Get Latest Main News
const News = await api.MainNews();
console.log(News);{
"code": 200,
"code_creator": {
"name": "Omindu_Dissanayaka",
"github": "@OminduDissanayaka",
"website": "https://www.omindu.dev"
},
"results": {
"title": "ඊශ්රායල ජාතිකයින්ට ප්රහාරයක් එල්ල කිරීමට සැලසුම් කළ බව කියන පුද්ගලයින් දෙදෙනෙකු අත්අඩංගුවට",
"news": "මෙරට රැදී සිටින ඊශ්රායල ජාතිකයන්ට ප්රහාරයක් එල්ල කිරීමට සැලසුම් කළ...",
"thumb": "https://cdn.hirunews.lk/Data/News_Images/202410/1729732149_1977919_hirunews.jpg",
"date": "Thursday, 24 October 2024 - 6:39",
"newsURL": "https://www.hirunews.lk/385878/ඊශ්රායල-ජාතිකයින්ට-ප්රහාරයක්-එල්ල-කිරීමට-සැලසුම්-කළ-බව-කියන-පුද්ගලයින්-දෙදෙනෙකු-අත්අඩංගුවට"
}
}Get Latest Trending News
const News = await api.TrendingNews();
console.log(News);{
"code": 200,
"code_creator": {
"name": "Omindu_Dissanayaka",
"github": "@OminduDissanayaka",
"website": "https://www.omindu.dev"
},
"results": {
"title": "ශ්රී ලංකාවේ බටහිර හා නැගෙනහිර වෙරළ තීරවලින් ඉවත් වන්නැයි, ඊශ්රායලය සිය ජනතාවගෙන් ඉල්ලයි (වීඩියෝ)",
"news": "පවත්නා තර්ජන හේතු කොටගෙන ශ්රී ලංකාවේ සංචාරක නිකේතනවලින් ඉවත් වන ලෙස...",
"thumb": "https://cdn.hirunews.lk/Data/News_Images/202410/1729682513_1674880_hirunews.jpg",
"date": "Wednesday, 23 October 2024 - 16:52",
"newsURL": "https://www.hirunews.lk/385838/ශ්රී-ලංකාවේ-බටහිර-හා-නැගෙනහිර-වෙරළ-තීරවලින්-ඉවත්-වන්නැයි-ඊශ්රායලය-සිය-ජනතාවගෙන්-ඉල්ලයි-වීඩියෝ"
}
}Get Latest International News
const News = await api.InternationalNews();
console.log(News);{
"code": 200,
"code_creator": {
"name": "Omindu_Dissanayaka",
"github": "@OminduDissanayaka",
"website": "https://www.omindu.dev"
},
"results": {
"title": "පිටසක්වල ජීවීන් සොයා උඩුගුවනට යන අභ්යවකාශ යානය",
"news": "පිටසක්වල ජීවීන්ගේ සලකුණු සෙවීම සඳහා ෆ්ලොරීඩාවෙන් Europa Clipper නම් අභ්යවකාශ යානය...",
"thumb": "https://cdn.hirunews.lk/Data/News_Images/202410/1728921378_9976226_hirunews.jpg",
"date": "Monday, 14 October 2024 - 21:26",
"newsURL": "https://www.hirunews.lk/384964/පිටසක්වල-ජීවීන්-සොයා-උඩුගුවනට-යන-අභ්යවකාශ-යානය"
}
}Get Latest Sport News
const News = await api.SportNews();
console.log(News);{
"code": 200,
"code_creator": {
"name": "Omindu_Dissanayaka",
"github": "@OminduDissanayaka",
"website": "https://www.omindu.dev"
},
"results": {
"title": "නවසීලන්ත සහ ශ්රී ලංකාව අතර පැවැත්වීමට නියමිත ක්රිකට් තරගාවලියේ කාල සටහන නිකුත් කෙරේ",
"news": "සංචාරක නවසීලන්ත සහ ශ්රී ලංකා ක්රිකට් කණ්ඩායම් අතර පැවැත්වීමට නියමිත...",
"thumb": "https://cdn.hirunews.lk/Data/News_Images/202410/1728927505_8411631_hirunews.jpg",
"date": "Monday, 14 October 2024 - 23:18",
"newsURL": "https://www.hirunews.lk/sports/384971/නවසීලන්ත-සහ-ශ්රී-ලංකාව-අතර-පැවැත්වීමට-නියමිත-ක්රිකට්-තරගාවලියේ-කාල-සටහන-නිකුත්-කෙරේ"
}
}Get Latest Entertainment News
const News = await api.EntertainmentNews();
console.log(News);{
"code": 200,
"code_creator": {
"name": "Omindu_Dissanayaka",
"github": "@OminduDissanayaka",
"website": "https://www.omindu.dev"
},
"results": {
"title": "Elon Muskගේ නවතම දොර දෙකේ රොබෝටැක්සිය (ඡායාරූප)",
"news": "එලෝන් මස්ක්, දොරවල් දෙකක් සහ සුක්කානම් රෝදයක් හෝ පැඩල් නොමැති රොබෝටැක්සියක් හඳුනවා දී තිබෙනවා...",
"thumb": "https://cdn.hirunews.lk/Data/News_Images/202410/1728638540_9280318_hirunews.jpg",
"date": "Friday, 11 October 2024 - 14:52",
"newsURL": "https://www.hirunews.lk/entertainment/384617/elon-muskගේ-නවතම-දොර-දෙකේ-රොබෝටැක්සිය-ඡායාරූප"
}
}Get Latest Business News
const News = await api.BusinessNews();
console.log(News);{
"code": 200,
"code_creator": {
"name": "Omindu_Dissanayaka",
"github": "@OminduDissanayaka",
"website": "https://www.omindu.dev"
},
"results": {
"title": "ලොවක් බලා සිටි iPhone 16 මිල ගණන් මෙන්න",
"news": "ඇපල් සමාගම iPhone 16 මාදිලිය ඊයේ නිල වශයෙන් වෙලඳපොළට නිකුත් කරනු ලැබුවා...",
"thumb": "https://cdn.hirunews.lk/Data/News_Images/202409/1725984481_5709076_hirunews.jpg",
"date": "Tuesday, 10 September 2024 - 19:31",
"newsURL": "https://www.hirunews.lk/business/381534/ලොවක්-බලා-සිටි-iphone-16-මිල-ගණන්-මෙන්න"
}
}Get News
const result = await api.getNews("https://www.hirunews.lk/385920/ට්රෑමි-සුළිකුණාටුවෙන්-පිලිපීනයේ-26-දෙනෙකු-ජීවිතක්ෂයට");
console.log(result);{
"code": 200,
"code_creator": {
"name": "Omindu_Dissanayaka",
"github": "@OminduDissanayaka",
"website": "https://www.omindu.dev"
},
"results": {
"title": "ට්රෑමි සුළිකුණාටුවෙන් පිලිපීනයේ 26 දෙනෙකු ජීවිතක්ෂයට",
"news": "පිලිපීනයට බලපා ඇති ට්රෑමි සුළිකුණාටුව හේතුවෙන් පුද්ගලයන් 26 දෙනෙකු ජීවිතක්ෂයට පත්ව...",
"thumb": "https://cdn.hirunews.lk/Data/News_Images/202410/1729759421_6149283_hirunews.jpg",
"date": "Thursday, 24 October 2024 - 14:14",
"newsURL": "https://www.hirunews.lk/385920/ට්රෑමි-සුළිකුණාටුවෙන්-පිලිපීනයේ-26-දෙනෙකු-ජීවිතක්ෂයට"
}
}Proxy Setup
Cloudflare Workers (Free)
You can run a tiny Cloudflare Worker to forward requests to hirunews.lk and use the worker URL as the proxy option for Hiru.
// Cloudflare Worker
export default {
async fetch(request) {
const url = new URL(request.url);
url.hostname = 'hirunews.lk';
return fetch(url.toString());
}
}Setup Steps
- Create an account at https://cloudflare.com
- Open the Workers section in the dashboard
- Create a new Worker and paste the code above
- Deploy the Worker and note the worker URL (e.g.
https://your-worker.workers.dev) - Use the Worker as proxy:
const api = new Hiru({
proxy: 'https://your-worker.workers.dev'
});Note: this Worker simply forwards requests to
hirunews.lk. Use it responsibly and obey the target site's terms of service and robots.txt.
Contributing
Contributions are welcome — open issues or submit pull requests. Please include tests where appropriate and follow the repository style.
License
MIT — see LICENSE file.
✍️ Author
@OminduDissanayaka — Hiru News Unofficial Scraper
Disclaimer
This is an unofficial package and is not affiliated with, endorsed by, or connected to Hiru News in any way. All content belongs to hirunews.lk.
This package is intended for educational purposes only. Use at your own risk. The author is not responsible for any misuse or legal issues arising from the use of this package.
