It will depend on the type of stain. If you use commercial spot removers, make sure to read the label, and follow specific care instructions and warnings provided by the manufacturer, as there are some spot removers that take off the protective coatings or break down dyes that are found on most carpets.
Please note: Test a small, hidden area first to make sure the solution won't discolor the carpet.
According to MarthaStewart.com, you may scoop up solids like berries and candies with a spoon, while for liquids like soft drinks or coffee use a cloth and then blot (don't rub!). Act fast - preferably while the stain is still wet as it's easier to remove the spot. Then rinse repeatedly.
If stain persists, you may use soapy water. As per Good Housekeeping, you can use a mixture of one tablespoon of liquid dish soap, one tablespoon of white vinegar, and two cups of warm water. Here's how:
1. Blot up as much of the coffee as you can.
2. Using a clean, white cloth, sponge the stain with the mixture.
3. Apply a little bit at a time, blotting frequently with a dry cloth until the stain disappears.
4. Finally, sponge with cold water and blot dry.
If improvement stops, dab on hydrogen peroxide (3%). Then wait for one hour. Use a white cloth or paper towel to blot the stain until it disappears. Place another clean cloth or paper towel on the stain and place something semi-heavy on top such as a book or brick so the stain will be drawn upward.
Properly cleaned and maintained carpet will last twice as long. Check out some tips for keeping your carpet looking new and fresh for years at Familyhandyman.com.