Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nasrulhazim/cb2cc247375f3a965090d47cadb3a469 to your computer and use it in GitHub Desktop.
Save nasrulhazim/cb2cc247375f3a965090d47cadb3a469 to your computer and use it in GitHub Desktop.
Get All Public Holidays for Malaysia States

Get All Public Holidays for Malaysia States

Installation

  1. Install PhantomJs
    • For Ubuntu 16.04, click here
  2. Install CasperJS
    • install globally: npm install -g casperjs

Usage

casperjs scrap-malaysia-state-holidays.js "Kuala Lumpur" 2017

States in Malaysia

  • Johor
  • Kedah
  • Kelantan
  • Kuala Lumpur
  • Labuan
  • Malacca
  • Negeri Sembilan
  • Pahang
  • Penang
  • Perak
  • Perlis
  • Putrajaya
  • Sabah
  • Sarawak
  • Selangor
  • Terengganu

Response

[
    {
        "date": "",
        "holiday": ""
    },
    {
        "date": "January 01",
        "holiday": "New Years Day"
    },
    {
        "date": "January 28",
        "holiday": "Chinese New Year "
    },
    {
        "date": "January 29",
        "holiday": "Chinese New Year Holiday"
    },
    {
        "date": "February 09",
        "holiday": "Thaipusam"
    },
    {
        "date": "May 01",
        "holiday": "Labour Day "
    },
    {
        "date": "May 10",
        "holiday": "Wesak Day "
    },
    {
        "date": "May 14",
        "holiday": "Mother's Day"
    },
    {
        "date": "June 03",
        "holiday": "Birthday of SPB Yang di Pertuan Agong "
    },
    {
        "date": "June 12",
        "holiday": "Nuzul Quran"
    },
    {
        "date": "June 25",
        "holiday": "Hari Raya Aidilfitri"
    },
    {
        "date": "June 26",
        "holiday": "Hari Raya Aidilfitri Holiday"
    },
    {
        "date": "August 31",
        "holiday": "National Day "
    },
    {
        "date": "September 01",
        "holiday": "Hari Raya Haji "
    },
    {
        "date": "September 16",
        "holiday": "Malaysia Day"
    },
    {
        "date": "September 21",
        "holiday": "Awal Muharram "
    },
    {
        "date": "October 18",
        "holiday": "Diwali"
    },
    {
        "date": "December 01",
        "holiday": "Mawlid"
    },
    {
        "date": "December 11",
        "holiday": "Birthday of The Sultan of Selangor"
    },
    {
        "date": "December 25",
        "holiday": "Christmas Day"
    }
]
var casper = require('casper').create();
var state = casper.cli.get(0);
var year = casper.cli.get(1);
casper.start('http://www.officeholidays.com/countries/malaysia/regional.php?list_year='+year+'&list_region='+state, function(){
//do nothing, at this stage we just open the page
});
casper.then(function(){
var info = this.evaluate(function(){
var arrayObjects = new Array();
jQuery(".list-table tr").each(function(index){
var tableResult = jQuery(this);
objResult = new Object();
objResult.date = tableResult.find('td').eq(1).find('span').html();
objResult.holiday = tableResult.find('td').eq(2).find('a').html();
if(objResult.date != '' && objResult.holiday != '')
{
arrayObjects.push(objResult);
}
});
return arrayObjects;
});
this.echo(JSON.stringify(info, undefined, 4));
});
casper.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment