Among stimulant drugs, cocaine deserves attention due to its high rates of seizures worldwide. This work presents the synthesis and characterization of hybrid molecularly imprinted polymers (MIPs) for use in preparing biological samples using a homemade microextraction in a packed sorbent device to extract cocaine. The MIPs synthesized using caffeine and cocaine as templates have been compared. Caffeine was used due to its low value and be easier to obtain than cocaine. Additionally, restricted access molecularly imprinted polymers (RAMIPs) were also produced for comparison purposes. The polymeric materials were characterized using scanning electron microscopy, textural analysis, Fourier transform infrared spectroscopy, and cross polarization/ magic angle spinning 13C nuclear magnetic resonance. The method optimization was performed using linear ion trap mass spectrometer to evaluate the effects of sample pH, type of eluent, washing solvent, adsorption cycles, and eluent volume. In the optimized method, RAMIPs indicated better cocaine extraction compared to MIPs. The quantitative study demonstrated that the developed method was able to accurately quantify cocaine in urine samples with values close to actual concentrations.