http://civilization.wikia.com/wiki/Espionage_(Civ5)
Broadly, the more science a city is producing, the quicker it is to steal technology from, However security buildings provide some defences, as to counterespionage agents.
If you are looking to steal tech, aim them for the ones with the most star ratings, as they'll be the highest science producers. If you are ahead in tech, don't bother as you can only steal a technology they have acquired but you haven't.
If you want to prevent tech theft (or at least improve chances of doing so) place them as security in your highest science cities. Bear in mind this is usually not optimal use of spies though, and unless you already have 100% alliance with all city states, you're better off using them for that.