2

I am looking for some stock symbol look-up API. I could able to query yahoo finance with a symbol & could able to retrieve the stock price & other details.

Is there any API for stock symbol searches

Any help would be great ..

Thanks

Nimmy
  • 5,051
  • 7
  • 33
  • 32

3 Answers3

2

You could use Python's urllib or the mechanise library to scrape the data from a website which publishes this data. Mechanise would be a better choice if the website requires some interaction before you can get hold of the data (like logging in).

EDIT - for getting stock quote for BT from Yahoo's UK site:

>>> import urllib
>>> import re
>>> data = urllib.urlopen('http://uk.finance.yahoo.com/q?s=BT&m=L&d=').read()
>>> re.search('<span id="yfs_l10_bt-a\.l".*?>([0-9.]+)', data).group(1)
'122.00'

The id in the regular expression was taken by viewing the source of the page and finding the id of the tag that surrounded the data required.

awatts
  • 1,008
  • 8
  • 13
  • 2
    You may be better off using [BeautifulSoup][1] than regular expressions for screen-scraping a web-page. [1] http://www.crummy.com/software/BeautifulSoup/ – johnsyweb May 26 '10 at 08:16
  • 1
    A similar question has already been asked here: http://stackoverflow.com/questions/1763310/yahoo-finance-api – awatts May 26 '10 at 21:23
  • urllib vs. urllib2 question: http://stackoverflow.com/questions/2018026/should-i-use-urllib-or-urllib2 – dmi May 28 '10 at 10:44
1

As an alternative to parsing the HTML you could be downloading a clean pre-formatted .csv file. See the tutorial at http://www.gummy-stuff.org/Yahoo-data.htm. Found it in the question awatts linked to.

dmi
  • 1,865
  • 3
  • 19
  • 19
  • Thanks for pointing that out. I hadn't really looked into it in detail, but that's a much better idea. Python has a csv module which would likely help too. – awatts May 30 '10 at 21:34
  • the gummy-stuff.org link how shows a letter from yahoo asking them to stop distributing the data so this answer should probably be removed. – unclejamil Apr 10 '15 at 05:03
0

Take a look at the Company Fundamentals API at http://www.mergent.com/servius

Eugene Osovetsky
  • 6,443
  • 2
  • 38
  • 59