# https://saturncloud.io/blog/how-to-extract-tables-from-html-with-python-and-pandas/
# https://search.brave.com/search?q=Passing+literal+html+to+%27read_html%27+is+deprecated+and+will+be+removed+in+a+future+version.+To+read+from+a+literal+string%2C+wrap+it+in+a+%27StringIO%27+object.+tables+%3D+pd.read_html%28str%28soup%29%29&source=desktop&summary=1&conversation=212132c0d053324192dd99
# https://search.brave.com/search?q=python3+StringIO&source=desktop&summary=1&conversation=784ebc2d4f47f7464a9ca6



import pandas as pd
from bs4 import BeautifulSoup
from io import StringIO

import urllib.request
import ssl

# Opens a website and read its
# binary contents (HTTP Response Body)
def url_get_contents(url):

	# Opens a website and read its
	# binary contents (HTTP Response Body)

	#making request to the website
	req = urllib.request.Request(url=url)
	f = urllib.request.urlopen(req)

	#reading contents of the website
	return f.read()

# https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error
ssl._create_default_https_context = ssl._create_unverified_context

webpage = url_get_contents('https://cset2.stcc.edu/~csetuser/pandas/index.html')
soup = BeautifulSoup(webpage, 'html.parser')
tables = pd.read_html(StringIO(str(soup)))

# Extract the table from the dataframe
table = tables[0]
print(table)

# Extract all tables from the dataframe
for i, table in enumerate(tables):
    print(f"Table {i + 1}:\n{table}\n")

