On the free side, Yahoo has historical data back to 1962 available in CSV format. It's not comprehensive in terms of stats (just the basics) or range (mostly focused on U.S. exchanges) but pretty decent -- most crucially, it supports "adjusted close" prices that take dividends & splits into account. Some of the other consumer friendly finance websites (MSN, BB, Morningstar, Google, etc) are ok too but I've come to prefer Yahoo.
I doubt you will find real-time quotes in a scraper-friendly format for free. It's only in the last few years that discount online brokers have started offering "free" real-time quotes when trading inside your account. If you already have such an account, see if your brokerage offers an API -- many do. If not, Interactive Brokers is a common recommendation for automation minded traders.
IMO, any kind of "real time" data is useless without Level II quotes. There are a handful of websites like this one that are open to the public, but they're clearly geared to avoid bots. Once your needs reach this level you'll need registration at minimum, and probably a small paid subscription / account maintenance fee.
When it comes to $$ services the major players are Bloomberg, Factset, and Thompson/Reuters. You can get just about any info imaginable...for the right price. Note: many of their services are oriented toward running your own data mining algorithms on their servers and returning only the result set, though usually you have the option of doing either. (Depending, of course, on what you're willing to pay.)
There are tons of smaller companies as well that specialize in different niches. As you can imagine, analysts & hedge fund managers & the like are willing to throw buckets of cash at anything that might give them an edge, so the competition and variety are large.
One issue you'll find as you expand your range is that different data providers use different identifiers for the same security. U.S. stocks are mostly ok; the problem arises with foreign exchanges, ETFs, indexes, and so on. There exist standards like ISIN, but unfortunately that's generally not what companies expect you type into their web forms or POST into their API.