Real Madrid are two points clear at the top of La Liga after grinding out a victory at bottom club Espanyol.