-
-
Save hosseinmasoomi/0d5f873ec54e5538d3f46264c82d4126 to your computer and use it in GitHub Desktop.
Array.from(document.querySelectorAll("li[class='eventHoliday ']"), (node => ({ | |
date:document.querySelector("input[type='text']").value +'/' + (Array.from(document.querySelectorAll("div[class='col-md-12']>div>div>span>span>span"), node => node.innerText).findIndex(x => x === node.innerText.split(" ")[1]) + 1).toString() + "/" + node.innerText.split(" ")[0].replace(/[۰-۹]/g, d => '۰۱۲۳۴۵۶۷۸۹'.indexOf(d)), | |
description: node.innerText.split(" ").slice(2).join(" ") | |
}))) |
thanks for your efforts. you claim that this script returns holidays for a year but it only returns holidays displayed in the specific page (the month displayed) . also the dates are not well formatted.
example:
[
{
"date": "/1/5",
"description": "ولادت امام علی علیه السلام و روز پدر [ ١٣ رجب ]"
},
{
"date": "/1/19",
"description": "مبعث رسول اکرم (ص) [ ٢٧ رجب ]"
},
{
"date": "/1/22",
"description": "پیروزی انقلاب اسلامی"
}
]
@mdbaniani you should run script in this url that is the yearly view of calendar, to get holidays for a year
@mdbaniani you should run script in this url that is the yearly view of calendar, to get holidays for a year
thx for clarifying
Thanks a lot!
(() => {
const persianDigits = '۰۱۲۳۴۵۶۷۸۹';
const faToEn = s => s.replace(/[۰-۹]/g, d => persianDigits.indexOf(d));
const year = document.querySelector("input[type='text']")?.value ?? "1404";
const monthElements = Array.from(document.querySelectorAll("div.col-md-12 > div > div > span > span > span"));
const monthNames = monthElements.map(el => el.innerText.trim());
const holidays = Array.from(document.querySelectorAll("li.eventHoliday")).map(node => {
const parts = node.innerText.trim().split(/\s+/);
if (parts.length < 3) return null;
const day = faToEn(parts[0]);
const monthName = parts[1];
const desc = parts.slice(2).join(" ");
const monthIndex = monthNames.findIndex(x => x === monthName) + 1;
return {
date: `${year}/${monthIndex}/${day}`,
description: desc
};
}).filter(Boolean);
console.log(JSON.stringify(holidays, null, 2));
copy(holidays);
})();
I think this is easiest way to get JSON output of the holidays. Just run the code on console of the target URL ( you can also select another year and get the data from it! ), maybe this helps...
اسکریپت بالا را در سایت time.ir در کنسول اجرا کنید و به صورت استاتیک تعطیلات هر سال شمسی را همراه با توضیحات داشته باشید