Skip to content

Instantly share code, notes, and snippets.

@RustyNails8
Created November 22, 2020 18:22
Show Gist options
  • Save RustyNails8/4df667510b7aa617b7b155c2f84669ae to your computer and use it in GitHub Desktop.
Save RustyNails8/4df667510b7aa617b7b155c2f84669ae to your computer and use it in GitHub Desktop.
Scrape tables from any website
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