A lot of dialogue in movies is dubbed for this very reason, it’s very hard to not pick up noise. What you can deal with is how close the mic is to you (which is why news reporters rely on hand held mics, not just the boom mike) and the pattern of the mic: a cardoid, hypercardoid or shotgun mic facing the opposite direction of the noise source would pick up less than an omnidirectional one (which is why the mics you see in studios are not used on a loud stage—not only are they fragile and expensive, they also tend to be omnidirectional).