Apparently always asking for thousands of discounts does not always work, but when there are only a few discounts, the number is not mentioned explicitly anywhere in the page. The solution is to combine two approaches. If the number of discounts is not found, try counting the number of discounts directly in the front page.
Apparently when there are 10 discounts or less the webpage does not mention the number of discounts like it does usually, so the script was terminating with a fatal error. Just testing, I saw you can request more discounts than they are available and the server will reply with everything it can, so by default we can request 1000 discounts (high-enough number, in theory) and always get the full list.