Scrapping Da Ma Cai 4D Results

Tips for scrapping drawing results from Da Ma Cai (a lottery in Malaysia) website. This method works as of 7 July 2024. This is an undocumented method and not officially supported, so it might not work in future.
Disclaimer
The information provided in this article is for educational purposes only. Web scraping practices and legalities can vary depending on the website and your location. It is your responsibility to ensure you have the necessary permissions before scraping data from any website. Scraping data without permission may violate the website's terms of service or even local laws.
Get Draw Dates
Draws are conducted every Wednesday, Saturday and Sunday at 7 PM, and some Tuesdays. So it is not always consistent. If you need to get draw results for different days, you need to know what are the draw dates.
Send a GET request to https://www.damacai.com.my/ListPastResult. It returns a JSON object with a single drawdate attribute. The value is a string containing recent draw dates separated by space. The dates are in "YYYYMMDD" format.
This is a bad design. They could have used an array instead of string. Take note of the trailing space in this string. I recommend ISO 8601 date format for APIs.
Example request
curl 'https://www.damacai.com.my/ListPastResult'
URL Link For Draw Results
To get the draw results, you must first retrieve an URL link (for a selected date). This link will direct you to the draw results.
Send a GET request to https://www.damacai.com.my/callpassresult?pastdate=<YYMMDD>. Replace "<YYMMDD>" with a draw date. You must include a HTTP header cookiesession: 363.
Example request
curl -H 'cookiesession: 363' 'https://www.damacai.com.my/callpassresult?pastdate=20240707'
Example result
{"link":"https://prddmcremt1.blob.core.windows.net/drawresult/DrawDate/20240707.json?sv=2014-02-14&sr=b&sig=gErL79ZbcEIDQ%2FlAmq6ZT1fOR%2FQqRWVk%2BslMtR0NXGE%3D&st=2024-07-07T15:10:38Z&se=2024-07-07T16:20:38Z&sp=r"}
It seems to be signed and valid for 1 hour.
Final Step
Send a GET request to the link URL. The response is draw results in JSON format. There is a number of spelling errors. "Past" is sometime spelt as "pass", "consolation" is sometime spelt as "consolidate". The misspelled words and inconsistent naming convention triggers my OCD 🤢.
Example request
curl 'https://prddmcremt1.blob.core.windows.net/drawresult/DrawDate/20240707.json?sv=2014-02-14&sr=b&sig=vRNxKXftDFgWH1fWnQOoaVliFAIE0MffQ6m5B%2FysBVU%3D&st=2024-07-07T15%3A14%3A19Z&se=2024-07-07T16%3A24%3A19Z&sp=r'
MAY THE SOURCE BE WITH YOU

