Novel magnetic molecularly imprinted nanoparticles (MMINs) were greenly synthesized by one-pot method with ketoprofen (KP) as template molecule and used as the adsorbent of magnetic solid-phase extraction (MSPE) for selective extraction of non-steroidal anti-inflammatory drugs (NSAIDs). By means of calculation simulation technology, N-vinyl pyrrolidone (NVP) and allylglycine (AG) were rapidly screened as suitable dual functional monomers. After that, self-assembly solution of KP-NVP/AG, magnetic source (Fe3+/Fe2+) and N,N-dimethylformamide were mixed in one pot, and then simple hydrothermal technology was utilized to quickly prepare MMINs with a total reaction period of 3.5 h. A series of characterized techniques were adopted to study the structure, morphology and magnetic property of prepared MMINs. Results indicated that the adsorption behavior of MMINs towards KP was well fit for Freundlich adsorption model and pseudo-second-order kinetics. Under the optimal conditions, the obtained MMINs exhibited satisfactory specific recognition capability. The imprinting factor and extraction capacity towards KP were as high as 6.73 and 15.6 mg/g, respectively. Combining with HPLC, accurate and reliable approach for the measurement of trace NSAIDs in environmental waters and human urine samples was developed. The established approach exhibited low limits of detection (0.0024–0.0029 and 0.0026–0.0045 μg/L for water and urine samples, respectively), good fortified recoveries (77.8–119 % for water samples and 78.3–120 % for urine samples) and satisfactory precision (RSDs ≤ 9.7 %).