In textbooks it is said that it would be better to launch a spacecraft towards the east to take benefit from the Earth's self-rotation. However, in TV we see that all rockets are launched vertically. It seems that it is because of technical difficulty in launching a rocket non-vertically. But is it true that after getting to some height, the rockets will turn their directions to the east?
I think you are mis-understanding. It dosn't matter which way you launch; it matters which way you orbit. No matter what direction you launch you still have Earth's eastward rotational energy. The reason you launch vertically is you want to get out of the thickest part of the atmosphere as quickly as possible to reduce your atmospheric drag; the fastest way to do that is vertically. It is fairly complex calculus to decide exactly how quickly to pitch over.
Just watch an old movie of a space shuttle launch. When they put the telescopic camera lenses on it, you can see it starting to pitch over from vertical into a circular orbit. They actually use the words "pitch over", spoken from mission control, as the rocket nozzles gimbal and the manouvere occurs.
East is the usual direction to "aim" for but as you can see from the other answers, it depends on the purpose of the payload.
After a vertical launch, which all spacecraft and space probe carrying rockets start from, this is followed by a pitch over of the vehicle into it's orbit. You can see the space shuttle on its "back", in a lot of still photos and movies as it orbits the Earth, then it had to be rolled 180 degrees and pitched up to utilise the heat shield/tiles effectively.
Shuttle launch view from an aircraft window.
There are two aspects to this question, east VS west and horizontal vs vertical.
east vs west
Launching into an eastwards (prograde) orbit takes less delta-v than a westwards (retrograde) orbit because the earths rotation gives a boost in the former case and a penalty in the latter case.
horizontal vs vertical
If the earth had no atmosphere or obstructions and rockets had unlimited thrust then the most efficient (in terms of delta-v) way to get into orbit would be to launch horizontally. The launch would consist of two "burns", one at ground level to set the apogee at the desired alititude and one at the apogee to circularise the orbit.
However our rockets don't have unlimited thrust and the earth does have an atmosphere. So we start off by launching vertically to get out of the thick part of the atmosphere as quickly as possible, minimise aerodynamic stresses on the rocket and avoid hitting the ground. Later when the air is thinner the rocket turns gradually towards the horizontal so that by the end of the launch burn it is thrusting mostly horizontally. It will then coast to apogee and circularise (especially for high orbits, circularisation may be handled by engines on the payload rather than the launch rocket as it only requires a relatively small amount of delta-v and it avoids needing to de-orbit the final stage of the launch rocket)
Whether it is launched horizontally towards the east, or vertically up into the atmosphere, the rocket already has the benefit of the boost from the spin of the Earth. This adds about 0.5 km/s to the speed of the rocket.
For example, if you release a ball from a roundabout (merry-go-round) of radius $R$ and angular speed $\omega$, then in the frame of the rotating roundabout the ball accelerates radially outward at $R\omega^2$, and deflects away from the direction of spin. But in the frame on the ground it flies off tangentially at constant speed $R\omega$ in the direction or rotation. If the speed you can impart to the ball is small compared with $R\omega$, it adds little to the ball's total speed relative to the ground if you throw tangentially (forwards) or radially (upwards).
An even bigger boost is obtained from leaving the Earth in the direction of the Earth's rotation about the Sun. This adds another 30 km/s to the speed of the rocket. See NASA's educational page Launch a rocket from a spinning earth.
If a rocket is launched horizontally, it will remain within the lower atmosphere for much longer. It will burn more fuel on such a trajectory because air density and therefore air resistance is highest close to the ground. Drag increases with speed through the atmosphere, so fuel consumption is least when the flight through the lower atmosphere is at the lowest speeds just after launch. Vertical launch gets the rocket out of the dense lower atmosphere in the shortest time, using the least amount of fuel.
See also :
In most cases you want the rocket to get into an (ideally circular) orbit around earth. To establish that, the rocket has to turn its direction from vertical to horizontal at some point. As you said, it is practicable to fly towards the east in order to use earth's rotation.
After establishing a stable orbit, you could do whatever you like, for example place a satellite in that orbit or fly to another celestial body.
But is it true that after getting to some height, the rockets will turn their directions to the east?
This is the case for rockets launched from an equatorial launch site for vehicles that are intended to be in an equatorial orbit. This is not the case for all vehicles. Some counterexamples:
Vehicles launched from the Cape intended to deliver cargo to the International Space Station turn to the northeast to match the Space Station's 51.6 degree inclination.
Vehicles launched from Vandenburg intended to place an Earth-observing satellite in a sun-synchronous orbit turn to the southwest to attain the ~98 degree inclination mandated for such an orbit. There's a penalty to be paid here: The launch vehicle has to overcome the eastward velocity that naturally results from launching from the rotating Earth.
Vehicles launched from Kodiak intended to place an Earth-observing satellite in a sun-synchronous orbit turn to the south to attain the ~98 degree inclination mandated for such an orbit. The high latitude of the Kodiak launch site reduces the penalty for launching into a retrograde orbit.
Vehicles launched from Palmachim on Israel's Mediterranean coast turn to the west so as to avoid having the launch vehicle fly over countries that are on less than friendly terms with Israel. There's an extreme penalty for these westward launches, about a 1/3 reduction in payload mass compared to an eastward launch into an equivalent altitude orbit.