I'm trying to extract data from html source using BeautifulSoup. This is the source
<td class="advisor" colspan="">
Here is my code:
soup = BeautifulSoup(html, 'html.parser')
tds = soup.find_all('td')
for td in tds:
if td["colspan"] == '':
col = 0
else:
col = int(td["colspan"])
However, I get this error:
ValueError: invalid literal for int() with base 10: ''
I know this error means '' cannot be transformed to integer, but why doesn't my 'if' work? I think this situation should go to
col = 0
rather than
col = int(td["colspan"])