I am trying to webscrape wikipedia's COVID-19 data chart for the US (https://en.wikipedia.org/wiki/Template:COVID-19_pandemic_data/United_States_medical_cases), and I am running into trouble with determining whether an HTML element contains text or not. I have tried using
element.text is not None
as an if conditional, but that simply allows the HTML element to put out nothing.
element.text != ''
has the same result. Is there anything else I could check for? Here is all my code
def getCases(page):
cases = []
firstCaseChild = page.find(title='January 21, 2020')
firstCaseChild2 = firstCaseChild.find_parent('th')
row = 0
column = 0
firstRow = []
for case in firstCaseChild2.find_next_siblings('td'):
if column == 55:
break
if case.text is not None:
firstRow.append(case.text)
column = column+1
print(case.text)
else:
firstRow.append('0')
column = column+1
print('0')