Get Major Index Components
Get major index component data from wikipedia with these 3 simple functions:
import pandas as pd
def get_sp500_components():
table = pd.read_html('https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')
data = table[0]
return data
def get_nasdaq100_components():
table = pd.read_html('https://en.wikipedia.org/wiki/Nasdaq-100#Components')
df = table[3]
return df
def get_dow30_components():
table = pd.read_html('https://en.wikipedia.org/wiki/Dow_Jones_Industrial_Average#Components')
df = table[1]
return df