Консоль выкидывает ошибку TypeError: string indices must be integers, при попытке передачи построчно
for i in range(j, len(property)):
k = j
write_to_csv(property[k])
k += 1
j = len(property)
Полный текст ошибки :
Traceback (most recent call last):
File "C:/Users/Danis/PycharmProjects/parser/parser_cian.py", line 116, in
get_offices(url)
File "C:/Users/Danis/PycharmProjects/parser/parser_cian.py", line 71, in get_offices
write_to_csv(property[k])
File "C:/Users/Danis/PycharmProjects/parser/parser_cian.py", line 82, in write_to_csv
a_pan.writerow((building['адрес'], building['площадь'], building['цена'], building['цена за м²'],
TypeError: string indices must be integers
def write_to_csv(property):
with open('cian_parser.csv', 'a', encoding='utf8', newline='') as file:
a_pan = csv.writer(file, delimiter=',')
for building in property:
a_pan.writerow((building['адрес'], building['площадь'], building['цена'], building['цена за м²'],
building['ссылка'], building['дата выгрузки']))
read_file = pd.read_csv(r'cian_parser.csv')
read_file.to_excel(r'cian_parser.xlsx', index=None, header=True)