The best defense against stains on the carpet is club soda. Keep several bottles on hand and reserve them for spills on any type of carpet. Blot as much of the spill as you can. Layer a few old towels over the spill and stand on them to soak up as much of the liquid as possible. Scrape up any solids first to avoid working them into the carpet fibers.
After you’ve blotted up as much as possible, pour club soda over the spill. Be generous and really pour it on. The carbonation will work to bubble the spill away from the fibers so you can blot again. Use clean, light-colored towels over the area and stand on them again.
Continue this process (club soda/blotting) until the stain is completely blotted and the towels are only wet with club soda. Make sure there is no trace of the spilled liquid. You can follow up with an effective carpet stain remover. Be sure to use the product as directed and don’t rub.