This paper describes the synthesis of a molecularly imprinted polymer by chemical oxidation of pyrrole as the functional monomer, and at the presence of guaifenesin as the template. The prepared polymer was used as adsorbent in molecularly imprinted solid‐phase extraction followed by spectrophotometric determination. Different parameters in the solid‐phase extraction including sample pH, adsorbent weight, washing solution, and elution solvent were studied to determine optimum conditions for isolation and enrichment of guaifenesin. The results showed guaifenesin was quantitatively adsorbed on the molecularly imprinted polymer at pH 6.0 and completely eluted with an ethanol–water solution (50% v/v). An enrichment factor of four with satisfactory recoveries (87.0–95.0%) was obtained. The solid‐phase extraction columns could be used for up to six consecutive elution‐loading cycles without significant decreases in the analyte recoveries. The method had a dynamic range of 3.0 × 10−6–1.5 × 10−4 mol/L with a limit of detection and limit of quantification of 1.4×10−6 and 4.5×10−6 mol/L, respectively. The proposed procedure was used for the extraction and determination of guaifenesin in different pharmaceutical formulations, with satisfying results being achieved.