我想确定一个 li 项目是否具有 .corsa-yes 类。如果是,我想附加到数组“状态”:“活动”。数据是从这个网站上抓取的 我已经尝试了以下代码,但我得到了
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"
})
慕容森
相关分类