I'm trying to convert a table I have extracted via BeautifulSoup into JSON.
So far I've managed to isolate all the rows, though I'm not sure how to work with the data from here. Any advice would be very much appreciated.
[<tr><td><strong>Balance</strong></td><td><strong>$18.30</strong></td></tr>,
<tr><td>Card name</td><td>Name</td></tr>,
<tr><td>Account holder</td><td>NAME</td></tr>,
<tr><td>Card number</td><td>1234</td></tr>,
<tr><td>Status</td><td>Active</td></tr>]
(Line breaks mine for readability)
This was my attempt:
result = []
allrows = table.tbody.findAll('tr')
for row in allrows:
result.append([])
allcols = row.findAll('td')
for col in allcols:
thestrings = [unicode(s) for s in col.findAll(text=True)]
thetext = ''.join(thestrings)
result[-1].append(thetext)
which gave me the following result:
[
[u'Card balance', u'$18.30'],
[u'Card name', u'NAMEn'],
[u'Account holder', u'NAME'],
[u'Card number', u'1234'],
[u'Status', u'Active']
]