-
-
Save saadmahboob/6c27ea2d081bfcb22f8ce560f15e6103 to your computer and use it in GitHub Desktop.
NYSE, NASDAQ, and AMEX stock list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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