当我使用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。
答案 0 :(得分:1)
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
是否为无,只有在不是时才打印出来。