Google and Yahoo have search API's that you can use for these tasks without breaking TOS. Most of the software apps around use the API's if you give them your key, or you may prefer to write your own script to use the API's.
Otherwise I guess you could just use normal search from your script, but keep it slow, the kind of speed you'd go if you were doing it manually, and leave it running until its done? depends how often you need to check the stats.