1 回答

TA贡献1853条经验 获得超18个赞
错误信息
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']}
]
添加回答
举报