代码拉取完成,页面将自动刷新
同步操作将从 Cppowboy/stock_data_crawler 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/python
from urllib import request
import csv
import sys
import numpy as np
def getTickers(percent):
file = open('./tickerList.csv', 'w')
writer = csv.writer(file, delimiter=',')
capStat, output = np.array([]), []
for exchange in ["NASDAQ", "NYSE", "AMEX"]:
url = "http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange="
repeat_times = 10 # repeat downloading in case of http error
for _ in range(repeat_times):
try:
print("Download tickers from " + exchange)
response = request.urlopen(url + exchange + '&render=download')
content = response.read().decode('utf-8').split('\n')
for num, line in enumerate(content):
line = line.strip().strip('"').split('","')
if num == 0 or len(line) != 9: continue # filter unmatched format
ticker, name, lastSale, MarketCap, IPOyear, sector, \
industry = line[0: 4] + line[5: 8]
capStat = np.append(capStat, float(MarketCap))
output.append([ticker, name.replace(',', '').replace('.', ''), exchange, MarketCap])
break
except:
continue
for data in output:
marketCap = float(data[3])
if marketCap < np.percentile(capStat, 100 - percent): continue
writer.writerow(data)
def main():
percent = 20
s = getTickers(percent) # keep the top N% market-cap companies
if __name__ == "__main__":
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。