The code is attached below
tables = android_soup.findAll(‘table’,{‘class’: ‘wikitable’})
print(len(tables))
android_table = tables[0]
print(android_table)
headers = android_table.findAll(‘th’)
print(len(headers))
print(headers[1].text)
column_titles = [ct.text[:-1] for ct in headers]
print(column_titles)
rows_data = android_table.findAll(‘tr’)[1:]
print(len(rows_data))
first_row = rows_data[0].findAll(‘td’,{})
for d in first_row:
print(d.text[:-1])
table_rows = []
for row in rows_data :
current_row =[]
row_data = row.findAll(‘td’,{})
for idx,data in enumerate(row_data):
if idx!=0 and idx!=2:
current_row.append(data.text[:-1])
else:
current_row.append(data.text)
table_rows.append(current_row)
print(table_rows)
filename = ‘android_version_history.csv’
with open(filename,‘w’, encoding = ‘utf-8’) as f:
header_string = ‘,’.join(column_titles)
header_string += ‘\n’
f.write(header_string)
for row in table_rows:
row_string = ""
row_string = ','.join(row)
row_string += '\n'
f.write(row_string)