Optical absorption in a semiconductor for $EQuoting from Solid State Electronic Devices (by Ben G. Streetman and Sanjay Banerjee):

A photon with energy less than $E_g$ is unable to excite an electron
  from the valence band to the conduction band. Thus in a pure
  semiconductor, there is negligible absorption of photons with $hv<E_g.$
   This explains why some materials are transparent in certain
  wavelength regions.

Does this mean that electrons don't absorb photons with $E < E_g$? If so, then how is it possible that an electron 'knows' the energy of the photon without absorbing it? 
 A: Absorption isn't an instant event. At the level of simple quantum mechanics, this system can be described as follows.
Evolution of electron in crystal is governed by Schrödinger's equation. External electromagnetic field, namely the light which we shine on the crystal, is a periodic addition to the Hamiltonian. When you start shining light at the crystal, electron in state $|E_1\rangle$ is quasiperiodically changing its state: basically it oscillates near $|E_1\rangle$. But if there's an energy level $E_2$ such that $h\nu=|E_2-E_1|$, probability increases that the electron will appear at that level when measured, i.e. its state after some time $t$ appears $\alpha(t)|E_1\rangle+\beta(t)|E_2\rangle$.
Why? This is very similar to mechanical resonance. Suppose you have a very heavy ball hanging on a rope of negligible mass. Applying some arbitrary frequency force on it won't make it oscillate much. But if you apply force at the eigenfrequency of this pendulum, then even a tiny force, applied for long enough time can make the oscillation amplitude quite high. "Somehow" the pendulum knows its eigenfrequency :)
When you have bands of allowed energies, then the role of $|E_2\rangle$ is played by any of the levels in the band satisfying $h\nu=|E_1-E_2|$. If $h\nu<E_g$, then there're no such levels, thus such radiation can't be absorbed.
Note that there're some differences from mechanical resonance: for instance, probability can't exceed $1$, so instead of unbounded increase it in fact oscillates when the radiation is supplied long enough time — it's so called Rabi cycle.
A: I would say in the same way a thick beam in a structure "knows" that you are trying to tear it off: it is temporarily displaced somewhat due to your effort, but then returns to its stable state. So the electrons are not totally immune to the photon (for example, the crystal acquires some minuscule momentum due to light pressure, if the photon is reflected from the crystal).
