In this work, magnetic molecularly imprinted polymer (MMIP) capable of selectively recognizing and adsorbing cordycepin was prepared. The MMIP was prepared using cordycepin as the template molecule, methacrylic acid and acrylamide as the functional monomer and ethylene glycol dimethacrylate as the crosslinker. The MMIP was analyzed using various techniques including transmission electron microscopy, thermogravimetric analysis, Fourier transform infrared spectroscopy, vibrating sample magnetometer and x-ray diffraction. The adsorption properties of MMIP were subsequently investigated, including adsorption isotherms, kinetics, selectivity, and reusability. In an aqueous solution, the maximum theoretical adsorption of MMIP was 35.806 mg/g. Finally, two practical applications of MMIP were studied. Our results showed that MMIP was able to increase the purity of cordycepin in the fermentation broth of Cordyceps militaris by 5.46 times and, using in situ isolation techniques, MMIP was able to increase the total cordycepin content obtained from liquid fermentation of C. militaris by 33.41%. These results demonstrated that these MMIPs exhibit excellent magnetic properties and possess specific adsorption capability for cordycepin, enabling rapid separation. They offer advantages such as cost-effectiveness, high specificity, and recyclability.