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]