Supercritical carbon dioxide is prepared by selecting suitable precursors and supercritical solvents, changing the pressure, temperature, pressure release rate, solvent ratio and holding time, and then preparing the carbon foam precursor. After oxidation, carbonization and graphitization, the carbon foam with well-developed pore structure, uniform pore size, high porosity and small pore size can be obtained.