首页 > 解决方案 > 如何处理'NoneType'对象在python中不可下标

问题描述

t[4].find("a")["href"].split('/')[4]在以下代码中,如果为 null 或不可用,我将如何处理 !

注意:此代码在扩展块中。

PlayersTransferhistoryResult.extend([
{
   "pId": pid[4],
   "Season": t[0].text.strip(),
   "Date": t[1].text.strip(),
   "Left": t[4].text.strip(),
   "LeftId": t[4].find("a")["href"].split('/')[4],
   "Joined": t[7].text.strip(),
   "JoinedId": t[7].find("a")["href"].split('/')[4],
   "MV": t[8].text.strip(),
   "Fee": t[9].text.strip(),
} for t in (t.find_all(recursive=False) for t in tr) ])

标签: pythonobjecthandlenonetype

解决方案


推荐阅读