Aflatoxins (AFs) such as AFB1, AFB2, AFG1, and AFG2 are some of the main sources of exogenous contamination in traditional Chinese medicines (TCMs). Contamination by these four AFs can occur in the process of planting, processing, production, storage, and circulation, and will affect the safety of TCM applications. In this work, we synthesized a macroporous covalent organic framework (COF) as the adsorbent for the online solid-phase extraction (SPE) of the four AFs. Monodisperse polystyrene microspheres were used as the sacrificial template for the creation of macropores. The physical properties of macroporous COF were characterized. The online SPE processes were optimized. The online SPE method coupled with a high-performance liquid chromatograph equipped with a UV detector was used to determine the amount of the four AFs in TCM samples, including lotus seed, Sterculia lychnophora, coix seed, Ziziphi spinosae semen, and malt. Using the optimized method, a linear calibration curve was obtained in the range of 0.05-100 ng/g. The limits of detection were 0.015-0.03 ng/g. The recoveries of the four AFs in TCM samples ranged from 80.0 % to 101 %. This study presents a feasible and effective approach for the detection of AFs at trace level.