The invention relates to a method for preparing a hydrogen sulfide corrosion inhibitor used in an offshore oilfield produced oil pipeline and belongs to the technical field of petroleum additives. The method comprises the following steps: uniformly mixing an imidazoline compound, SPAN-80, rosin amine polyoxylethylene ether, sodium alga acid, methyl propanediol and ethanol, thereby obtaining a mixture I; uniformly mixing sodium chromate, sodium nitrite, sodium pyrrolidone carboxylate, hydroxyl ethyl benzoate, zinc borate, magnesium borate, dipentaerythritol, hydrogenated soya bean lecithin, triethylamine and propyl alcohol, thereby obtaining a mixture II; and uniformly mixing the mixture I, the mixture II, sodium benzoate, ammonium benzoate, sodium gluconate, sodium acrylate, thiosemicarbazide, carboxymethyl chito-oligosaccharide vanillic aldehyde Schiff base, thereby obtaining the hydrogen sulfide corrosion inhibitor. The corrosion inhibitor provided by the invention can effectively achieve a corrosion inhibition effect on the hydrogen sulfide in the pipeline under high salt conditions.