Сообщение об ошибке
TypeError: аргумент типа 'NoneType' не повторяется
, потому что элемент имеет no class
, сначала нужно проверить, еслион существует или сравнивается с массивом
if next_li.get("class") == ["corsa-yes"]:
# or check it first
if next_li.get("class") and "corsa-yes" in next_li.get("class"):
Я изменяю 'STATUS': "active"
на 'ACTIVE_TIME': '10:35'
и полный код
departure_time = []
active_time = None
for li in medmar_live_departures_table:
next_li = li.find_next_sibling("li")
while next_li and next_li.get("data-toggle"):
if next_li.get("class") == ["corsa-yes"]:
active_time = next_li.strong.text
departure_time.append(next_li.strong.text)
next_li = next_li.find_next_sibling("li")
medmar_live_departures_data.append({
'ROUTE' : li.text,
'ACTIVE_TIME' : active_time,
'DEPARTURE TIME' : departure_time
})
departure_time = []
Результат
[
{'ROUTE': 'ISCHIA » PROCIDA', 'ACTIVE_TIME': '10:35', 'DEPARTURE TIME': ['06:25', '10:35']},
{'ROUTE': 'PROCIDA » NAPOLI', 'ACTIVE_TIME': '07:05', 'DEPARTURE TIME': ['07:05', '11:15']}
]