Skip to content

Instantly share code, notes, and snippets.

@tristanwietsma
Created October 30, 2013 04:57
Show Gist options
  • Save tristanwietsma/7227411 to your computer and use it in GitHub Desktop.
Save tristanwietsma/7227411 to your computer and use it in GitHub Desktop.
NYSE, NASDAQ, and AMEX stock list
import requests
class Stock:
def __init__(self, exc, symb, name, link):
self.exchange = exc
self.symbol = symb
self.name = name
self.link = link
def __str__(self):
return '%s\t%s'%(self.exchange, self.symbol)
def __lt__(self, other):
return self.symbol < other.symbol
stocks = []
base_url = "http://www.nasdaq.com/screening/companies-by-industry.aspx"
for exchange in ['NASDAQ', 'NYSE', 'AMEX']:
url = base_url + "?exchange=%s&render=download"%exchange
req = requests.get(url)
for line in req.text.split('\n')[1:]:
if line.strip() == '': continue
cols = [c.strip('\"') for c in line.split('","')]
symbol = cols[0]
name = cols[1]
link = cols[8]
stk = Stock(exchange, symbol, name, link)
stocks.append(stk)
stocks.sort()
for i in range(len(stocks)):
print i+1, stocks[i]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment