A relatively simple nonempirical formula for the imaginary part of the optical potential for electron scattering is derived from a quasifree-scattering model with Pauli blocking in which the target is treated as a free-electron gas. The resulting absorption potential is local and energy dependent and is a function of the electron density of the target. This model is tested for electron-helium and electron-neon scattering at 30-3000 eV. For these tests the real part of the potential is also approximated by a local expression, which is partitioned into static, exchange, and polarization terms. Reasonably good agreement with experimental data is obtained for the elastic integral, absorption, and elastic differential cross sections.