Если я правильно понял задачу то приблизительно вот так можно решить через bs4:
# pip install bs4 openpyxl pandas
# Если не установлены
import pandas as pd
from bs4 import BeautifulSoup as Soup
from bs4.element import Tag
if __name__ == '__main__':
with open('test.html', 'r', encoding='utf-8') as html:
soup = Soup(html.read(), 'html.parser')
rows = soup.find_all('tr')
headers_row: Tag
headers_row = rows[1]
headers = {td.text.strip(): num for num, td in enumerate(headers_row.find_all('td'))}
constructor = {h: [] for h in headers}
for row in rows[2:]: # Вот здесь нужно уточнить структуру файла из которого читаем данные
# Тоесть как там располагаются строки относительно друг друга
# Тоесть больше строк нужно для понимания структуры в исходнике
values = [val.text.strip() for val in rows[2].find_all('td')]
for key in constructor:
constructor[key] += [values[headers[key]]]
pd.DataFrame(constructor).to_excel('./test.xlsx', engine='openpyxl', index=False)
На выходе получаем вот такой excel

Если нужны только несколько конкретных столбцов то:
with open('test.html', 'r', encoding='utf-8') as html:
soup = Soup(html.read(), 'html.parser')
rows = soup.find_all('tr')
headers_row: Tag
headers_row = rows[1]
headers = {td.text.strip(): num for num, td in enumerate(headers_row.find_all('td'))}
constructor = {
'Prim': [],
'PrimRadio': []
}
for row in rows[2:]:
values = [val.text.strip() for val in rows[2].find_all('td')]
for key in constructor:
constructor[key] += [values[headers[key]]]
pd.DataFrame(constructor).to_excel('./test.xlsx', engine='openpyxl', index=False, encoding='cp1251')
P.S. Но чисто через pandas
как здесь уже предложили как мне кажется изящней
UUPD Для большого количества строк
# Время выполнения около 4х минут на 53000 tr
import re
import pandas as pd
from bs4 import BeautifulSoup as Soup
from progressbar import ProgressBar
# прогресс бар для антуражу. установка pip install progressbar2
with open('test.html', 'r', encoding='utf-8') as html:
f = html.read()
iterator = re.finditer(r'<TR>.+?</TR>', f, flags=re.S)
iter_len = len(re.findall(r'<TR>.+?</TR>', f, flags=re.S))
next(iterator)
headers_row = Soup(next(iterator).group(0), 'html.parser')
headers = {td.text.strip(): num for num, td in enumerate(headers_row.find_all('td'))}
constructor = {
'Prim': [],
'PrimRadio': []
}
def get_values(html_tag: str):
soup = Soup(html_tag, 'html.parser')
values = [val.text.strip() for val in soup.find_all('td')]
for key in constructor:
constructor[key] += [values[headers[key]]]
iter_count = 0
with ProgressBar(max_value=iter_len) as bar:
while True:
try:
get_values(next(iterator).group(0))
iter_count += 1
bar.update(iter_count)
except StopIteration:
pd.DataFrame(constructor).to_excel('./test.xlsx', engine='openpyxl', index=False, encoding='cp1251')
break
html.parser
из стандартной библиотеки, илиbeautifulsoup4
). Записать данные в xlsx файл можно с помощью библиотекиopenpyxl