Итак, я отредактировал код, предоставленный @KarthickMohanraj, для реализации первого шага, то есть чтения файла html
, сохраненного локально. Окончательный код выглядит следующим образом:
from bs4 import BeautifulSoup
import pandas as pd
# opens html file saved locally
filepath = 'Aluminium_Profiles_profiles.html'
f = open(filepath, 'r', encoding='utf8', errors='ignore')
# reads html code as string
s = f.read()
# parse html string with BeautifulSoup
soup = BeautifulSoup(s) #Provide the html code of the url in string format as input over here
# The table id which you want to extract from this html is "resourceBenchmarkTable".
# So let's extract the html of this table alone from the entire html
extracted_table_html = str(soup.find_all("table",id="resourceBenchmarkTable"))
#Now, convert the specific extracted html of table into pandas dataframe
table_df = pd.read_html(extracted_table_html)[0]