I hacked together some pretty simple code, which I thought should allow me to screen scrape various tables from a URL. Here is my code.
import pandas as pd
import requests
from bs4 import BeautifulSoup
res = requests.get("https://www.federalreserve.gov/releases/h8/current/default.htm")
soup = BeautifulSoup(res.content,'lxml')
table = soup.find_all('table')[1]
df = pd.read_html(str(table))
print(df)
I am trying to grab data from table number 1, but when I run the code I get this error:
IndexError: list index out of range
I would like to enter a table number and get the relevant data from that specific table. There are a total of 11 tables on the page. What am I doing wrong?