'Huangguan' pear has significant social and economic value, and phosphorus, as one of the three main mineral elements of plants, has an irreplaceable effect on the normal growth of 'Huangguan' pear trees. The objective of this study was to predict the content of phosphorus in the pulp and peel of ‘Huangguan’ pears nondestructively and conveniently by using near-infrared spectroscopy (900–1700 nm) technology. First, twelve algorithms are used to preprocess the original spectral data, and the partial least squares regression algorithm and the gradient boosting regression tree algorithm are used to build a full-band prediction model based on the original spectral data and the processed spectral data. The characteristic wavelengths were extracted using genetic algorithms, followed by establishing a characteristic wavelength prediction model. The prediction accuracy of the models was evaluated according to the coefficient of determination R² and the relative analysis error RPD. The study found that the best prediction model for predicting phosphorus content in the pulp of 'Huangguan' pear was MSC-GA-PLSR, which had R²=0.843 and RPD=1.857 in the modelling set and R²=0.989 and RPD=7.041 in the prediction set. The best prediction model for predicting phosphorus content in the peel of ‘Huangguan’ pear was SG+SNV+FD-GA-PLSR, which had R²=0.991 and RPD=7.470 in the modelling set and R²=0.974 and RPD=4.414 in the prediction set, and the effect was good and met expectations. The results demonstrated that near-infrared spectroscopy could successfully achieve nondestructive detection of phosphorus content in the pulp and peel of 'Huangguan' pears.