for line in lines:
if '"brand":' in line:
currentbrand = parseline(line)
else:
row_data = [currentbrand]
for i in range(5):
row_data.append(parseline(lines.pop(0)))
data.append(row_data)
print(row_data)
def parseline(line):
values = line.replace('"','').split(':')
if len(values) == 2:
return values[1].strip()
else:
return ''
import pandas as pd
def parseline(line):
values = line.replace('"','').split(':')
if len(values) == 2:
return values[1].strip()
else:
return ''
with open("data4.html", encoding='utf-8') as file:
lines = file.readlines()
data = []
headers = 'brand', 'number', 'numberFix', 'short_number', 'crossType', 'reliable'
currentbrand = []
for line in lines:
if '"brand":' in line:
currentbrand = parseline(line)
else:
row_data = currentbrand
for i in range(5):
row_data.append(parseline(lines.pop(0)))
data.append(row_data)
df = pd.DataFrame(data, columns= headers)
df.toexcel('output.xlsx', index=False)
Traceback (most recent call last):
File "C:\Users\analitik\PycharmProjects\python_pars_ceni\second_obr_excel.py", line 21, in
row_data.append(parseline(lines.pop(0)))
^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'append'