Start by pretreating your carpet by using a carpet cleaner with stain resistant properties. This helps keep those stains from setting in. The next step is to be prepared. The stains are going to happen, so you might as well keep a clean cloth and some cleaning agents ready at a moments notice.
When the stain happens, grab the cloth and the cleaner and dab don't rub the carpet. All rubbing does is push the stain into the fibers of the cloth and possibly the padding of the carpet. Once it gets there, good luck every getting the stain completely out.