http://www.google.com/apis/
They are allowed a number of automated queries per day if they use the Google Web API. They probably don't use the API, and instead simply do a http query, and scrape the values from the html. The legalities of this are probably a little gray.
The most likely reason why the numbers are not consistent is because Google has a huge number of servers, and they don't have the exact same data all the time. So depending on which machine handles your query, you may not get the same number.