Python – Reading Financial Data From Internet
Reading financial data from the internet is sometimes challenging. In this short article with two python snippets, I will show how to read it from Wikipedia and from and from API, delivering in JSON format:

Reading the data from the API is actually not tough, if you have experience reading JSON, with nested lists. If not, simply try with trial and error and eventually you will succeed:
import numpy as np
import pandas as pd
import yfinance as yf
import requests
from datetime import datetime
def get_nasdaq_tickers_from_api():
headers={
"User-Agent":"Mozilla/5.0",
"Accept":"application/json"
}
url = "https://api.nasdaq.com/api/quote/list-type/nasdaq100"
response = requests.get(url, headers=headers, timeout=10)
tickers = [item["symbol"] for item in data["data"]["data"]["rows"]]
return tickers
With the reading from wikipedia, it is actually even easier – the site works flawlessly with pandas, and if you count the tables correctly, you would get what you want:
def get_nasdaq_tickers_from_wikipedia():
wiki_url = "https://en.wikipedia.org/wiki/Nasdaq-100"
tables = pd.read_html(wiki_url)
components_table=tables[4]
tickers=components_table["Ticker"].tolist()
return tickers
You might want to combine both sources, just in case:
tickers = list(set(get_wiki_tickers() + get_nasdaq_api_tickers()))
The YouTube video for this article is here:
The GitHub code is there – GitHub
Enjoy it! 🙂