Created
November 22, 2020 18:22
-
-
Save RustyNails8/4df667510b7aa617b7b155c2f84669ae to your computer and use it in GitHub Desktop.
Scrape tables from any website
This file contains 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 pandas as pd | |
url = r'https://en.wikipedia.org/wiki/List_of_S%26P_500_companies' | |
tables = pd.read_html(url) # Returns list of all tables on page | |
print(tables) | |
sp500_table = tables[0] # Select table of interest | |
print(sp500_table) | |
# https://stackoverflow.com/questions/6325216/parse-html-table-to-python-list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment