如何在解析器 (python) 处替换或删除 None

How to replace or delete None at parser(python)

当我使用 BeautifulSoup 解析网站时,我得到:

None
offer_15542518
None
None
None
None
None
None
None
None
None
None

代码:

soup = BeautifulSoup(html)
projects =[]
table = soup.find('table', class_='objects_items_list')
for row in table.find_all('tr'):
    internal_id = row.get('id')
    print( internal_id )

如何去掉None?我只需要id。

soup = BeautifulSoup(html)
projects =[]
table = soup.find('table', class_='objects_items_list')
for row in table.find_all('tr'):
    internal_id = row.get('id')
    if internal_id is not None:
        print( internal_id )

最简单的方法就是检查 internal_id 是否为 None,如果不是则打印它。