【发布时间】:2023-03-03 00:03:02
【问题描述】:
我正在使用 beautifulsoup 执行以下操作:section = soup.findAll('tbody')[0]
如果 BS4 找不到 tbody,如何使用第一个列表项设置类似的变量...而不抛出异常:IndexError: list index out of range?
有什么想法吗?
【问题讨论】:
-
section = soup.find('tbody')。如果tbody不存在,section将是None。
标签: python list exception python-2.7 beautifulsoup