Sample pretreatment is an essential procedure in pesticide analysis, as the matrix effect can significantly influence the results. In this study, a covalent organic framework (COF) was synthesized using 1,2,4,5-tetrakis-(4-formylphenyl)benzene (TFPB) and benzidine (BD) to mitigate the matrix effect in vegetable and fruit samples. This COF was then used to develop a solid-phase extraction (CSPE) method. In addition, the COF was used to create a magnetic COF (MCOF) for use in magnetic solid-phase extraction (MSPE). The synthesized COF and MCOF were thoroughly characterized using scanning electron microscopy (SEM) for morphological analysis, Fourier-transform infrared spectroscopy (FT-IR) for chemical bond identification, and N2 adsorption–desorption measurements for porosity and surface area assessment. Key pretreatment parameters such as buffers, dilution rate, sorbent dosage, extraction time, elution solvent, and reuse number were optimized. The developed CSPE and MSPE showed excellent purification ability for the matrix of vegetable and fruit samples. The reuse test demonstrated that the synthesized COF and MCOF can be reused up to 15 times. Moreover, the developed CSPE and MSPE showed acceptable recoveries in spiked recovery tests, suggesting that these pretreatment methods were feasible for sample purification in pesticide analysis.