a piece of html code:
<td class="advisor" colspan="">
I use beautifulsoup to obtain the information of it.
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 my 'if' does not work? I think this situation should go to
col = 0
rather than
col = int(td["colspan"])
Aucun commentaire:
Enregistrer un commentaire