Synthesis of 1,3,5,7-tetranitro-1,3,5,7-tetraazacyclooctane and 1,3,5-trinitro-1,3,5-triazacyclohexane by the Bachmann process leads to a mixture of both. The separation of 1,3,5,7-tetranitro-1,3,5,7-tetraazacyclooctane and 1,3,5-trinitro-1,3,5-triazacyclohexane from their mixture is difficult because the sizes and physical properties of these homologous compounds are similar. For this purpose, seven molecularly imprinted polymers have been synthesized for each explosive, and a selective solid-phase extraction procedure has been developed. A molecularly imprinted polymer, synthesized with 1,3,5,7-tetranitro-1,3,5,7-tetraazacyclooctane as the template, methacrylic acid as the monomer and trimethylolpropane trimethacrylate as the cross-linking agent in a molar ratio of 1:8:8 showed the best separation capability. A packed cartridge containing this polymer can be reused for 23 solid-phase extraction cycles without repacking, and the total separation capability toward 1,3,5,7-tetranitro-1,3,5,7-tetraazacyclooctane reached 6.81 mg per gram of polymer. 1,3,5-Trinitro-1,3,5-triazacyclohexane was not detected in the separated 1,3,5,7-tetranitro-1,3,5,7-tetraazacyclooctane by high-performance liquid chromatography and vice versa. This newly developed method had the advantages of high recovery (100%) and purity, environmental friendliness, and room temperature operability. This study showed that some molecularly imprinted polymers that cannot absorb target analytes well in the solvent in which the polymers were polymerized might have high-binding capacity for the analytes and show imprinting effects in other solvents.