我想确定li项目是否有该类。corsa是的。如果是,我想附加到一个数组'STATUS':“active”。数据是从this website中刮取的 我试过下面的代码,但是
if "corsa-yes" in next_li.get("class"):
TypeError: argument of type 'NoneType' is not iterable
这是我的密码
medmar_live_departures_table = list(soup.select('li.tratta'))
departure_time = []
for li in medmar_live_departures_table:
next_li = li.find_next_sibling("li")
while next_li and next_li.get("data-toggle"):
departure_time.append(next_li.strong.text)
next_li = next_li.find_next_sibling("li")
medmar_live_departures_data.append({
'ROUTE' : li.text,
'DEPARTURE TIME' : departure_time,
})
if "corsa-yes" in next_li.get("class"):
medmar_live_departures_data.append({
'STATUS': "active"
})
错误消息
因为元素有
no class
,您需要首先检查它是否存在或与数组进行比较我将
'STATUS': "active"
更改为'ACTIVE_TIME': '10:35'
,并完成代码结果
相关问题 更多 >
编程相关推荐