Various functionalized β-ketoenamine COFs (TpPa-Rs, R= −1, -SO3H, -NO2, -NH2, -COOH and -CH3) were synthesized, characterized and employed to study the effect of microenvironment on sulfamerazine (SMR) capture. The results showcased that the sulfonic acid group enhances the affinity of COFs to SMR, while the amino group has the opposite effect. Consequently, sulfonic acid functionalized COF (TpPa-SO3H) was selected for SMR adsorption in detail. The adsorption process followed the pseudo-second-order kinetic model and reached equilibrium within 4 h at the initial concentration of 50 mg/L. The Langmuir isotherm model fits the adsorption isotherm well. The maximum adsorption capacity of TpPa-SO3H for SMR is calculated to be 174 mg/g. Furthermore, it also has been proved that the adsorption process is spontaneous and endothermic. Two main adsorption interactions including Lewis acid-base interaction and hydrogen bond interaction were responsible for SMR uptake, which were deduced by XPS and FT-IR characterizations. Therefore, TpPa-SO3H is expected to serve as a promising porous adsorbent to remove SMR from water, and COFs with unique active sites for adsorption can be obtained via tuning functional groups.