from bs4 import BeautifulSoup
import json

with open("navas.html") as f:
    soup = BeautifulSoup(f ,'html.parser')  
    tablerows = soup.find_all(class_='data-set') 
    thead_ = soup.find("thead") 
    data_result = []
    thead={}
    if thead_:
        thead_ = thead_.find_all("th") 
        for i in range(len(thead_)):
            thead[i] = thead_[i].text.strip().lower()
    # print(thead) 
    for table_row in tablerows:
        data_row =  table_row.find_all("td")  
        # print(data_row)
        if thead:
            data_items = {}
            for index in thead: 
                data_items[thead[index]] = data_row[index].text  
                
        data_result.append(data_items)
        
    print(data_result)
    sort_data = sorted(data_result, key=lambda last_name: last_name['last_name'])
    print(sort_data)
with open('Expected_Result.json', 'w'  ) as f:
    json.dump(data_result,f, indent = 2)  
with open('Extra_Expected_Results.json', 'w'  ) as f:
    json.dump(sort_data,f, indent = 2)  