Reputation: 33
I have extracted the below web based data as a list using Beautiful Soup
. On the original website it's a table of numbers:
[<td class="right">113</td>, <td class="right">
89 </td>, <td class="right last">
<b>117</b> </td>, <td class="right">113</td>, <td class="right">
85 </td>, <td class="right last">
<b>114</b> </td>, <td class="right">100</td>, <td class="right">
56 </td>, <td class="right last">
<b>84</b> </td>]
What's the most efficient way to create a list of numbers from this data? Ideally I'd like to extract the tags using Beautiful Soup but I can't figure out how to do this from the documentation.
My original Soup code is:
print soup.find_all('td', 'right') #printing this produces the above data
numbers_data = [] #my attempt to extract tags
for e in soup.find_all('td', 'right'):
numbers_data.append(e.extract())
print numbers_data
Both return the same list.
Upvotes: 2
Views: 2314
Reputation: 1787
numbers_data = [int(e.text) for e in soup.find_all('td', 'right')]
print numbers_data
Upvotes: 1