Put your spy in your capitol as counter measure and wait, if your have high enough science to attract spies. ie you need to have science your rival wants. So this is obviously easier to get on the lower difficulties where you is bound to be science leader independent of your play style.
You get your first spy when you enter the Renaissance Era.