I used to work at a place that made professional carpet cleaning equipment and the cleaning agents that went with them.
As an engineer designing their products, I had to go to school to get certified as a carpet care professional.
They actually had carpet on the floor of the machine shop to make sure it got REAL dirty. They would then test cleaning agents and processes to se what would get it clean. I was there for 18 years and it never ceased to amaze me what these cleaners could get out of carpet.
#1 rule, NEVER rub a spot while cleaning it, you will only spread it. Use a solvent that will break down the spot and not damage the carpet and then LOTS of blotting with clean white towels or white paper towels to draw it out of the carpet. I have seen color of towels and the printing on paper towels transfer to the carpet. If it does need some agitation use a stiff bristle brush and small circular movements, just enough to agitate it but not enough to spread it.
Carpet can be made from many different materials, each will have resistance to different chemicals and be safe with different chemicals but also damaged by different chemicals, so always test the cleaner you are about to use in an inconspicuous place.
With proper technique I have had to clean a bright red Automatic Transmission Fluid spill out of my living room light beige carpet.
Unfortunately the recipe for the cleaner is not something that could be reproduced at home, there are active ingredients that are only a few ounces into a 250 gallon batch. and that batch makes over 6000 lbs of cleaner. Plus the recipe is a closely guarded company secret. It was a real bummer when they had to stop using 1,1,1-Trichloroethane in the recipe.