Let's talk scale
Creating a creature that eats planets for breakfast requires some interesting considerations on scale. The Earth ($\oplus$) is heavy: $M_\oplus = 5.97 \times 10^{24}\,\text{kg}$. The Earth is one of the lighter planets out there, yet it is massive enough that gravity pulled it into an almost perfectly spherical shape, creating pressures and temperatures in the inner core are comparable to the photosphere of the sun $(5\,777\,\text{K})$.
Why is this important? Put quite simply, anything that eats a planet has to be on roughly the same scale as a planet (probably no less than a tenth of the mass). I believe it could work, but it will be difficult! I see two main options:
1. Eat smaller asteroids / portions of planets
If you don't want your whale to be planet-sized, you can have it consume much smaller asteroids and comets instead of planets, or if you don't mind bending the whale analogy a bit, you can have your whale pulverize portions of a planet's crust from orbit with powerful lasers, missiles, etc., and then "swim" through the atmosphere scoop up the small dust and rock particles from the atmosphere (this is very similar to how whales actually eat, more or less by swimming along with their mouth open).
2. You simply make one gigantic whale!
The above heading carries the obvious risk of stating the obvious. However, I can help with the details:
Your whale needs something to prevent it from collapsing under its own gravity. At planetary masses, ordinary steel structures won't be sufficient. However, ironically, the bigger you build it (while keeping the mass the same), the weaker the gravity on the surface. The more hollow it is, and the rounder you can make it, the better. Gravity is strongest in the middle of the mass. If you can then create equivalent outward pressure that won't destroy the whale, it just might work!
Planetary Approach
If you do go with a planetary-scale whale, how it approaches planets might be of some interest to your story. It will be massive enough that its own gravity will pull the planet towards it (and the planet will pull the whale, as well). As they get nearer and nearer, without any added propulsion, they will accelerate to rather high speeds. If they collide after an uncontrolled approach, the energy released would be tremendous (and probably too much for your whale to survive, assuming you want plausible science).
So what do you do?
Caution: Fiction ahead!
I would give your whale some kind of strong propulsion system that can accelerate your whale to some fraction of the speed of light. Conventional propulsion would require enormous amounts of energy, and this energy would likely vaporize the target planet. Thus, this might be where you ask your readers to suspend their disbelief while you add a bit of sci-fi magic to your story, giving your whale some kind of fictional propulsion system that bends (or, rather, flattens) the surrounding space or uses some kind of anti-gravity to allow the whale to approach and eat the planet as slowly and dramatically as you like.