We report electron-atom Compton scattering experiments on the H2 and D2 molecules. Energy-loss spectra of electrons quasielastically backscattered at an angle of 135° are measured as a function of azimuthal angle at an incident electron energy of 2.0 keV. Momentum distributions of the H and D atoms due to molecular vibration are extracted from the experimental data by using a protocol that we propose here. The results are successfully compared with theoretical ones predicted by the molecular vibrational wave functions. It is shown that electron-atom Compton scattering has a unique ability to provide direct information about intramolecular motion of each atom with different mass numbers.