Most carpet stains come out if you treat them before they set. The method depends on what caused the stain.
Press a clean white cloth firmly onto the stain. Scrubbing spreads the stain and pushes it deeper into the fibers.
Mix one cup warm water, half a teaspoon dish soap, and one tablespoon white vinegar. Spray lightly — don't soak. Let sit five minutes, blot, repeat until the stain lifts.
Rinse with clean water and blot dry. Place a dry towel over the spot with weight on top for an hour. Vacuum once fully dry.
Never use hot water — it sets protein stains. Never scrub. Never soak the carpet — moisture reaching the backing causes mold.