BeautifulSoup html table scrape - will only return last row
<p>I am attempting a simple scrape of an HTML table using BeautifulSoup with the following:</p>

<pre><code>import urllib
import urllib.request
from bs4 import BeautifulSoup

def make_soup(url):
    page = urllib.request.urlopen(url)
    sdata = BeautifulSoup(page, 'html.parser')
    return sdata

url = 'http://www.satp.org/satporgtp/countries/pakistan/database/bombblast.htm'
soup = make_soup(url)

table = soup.findAll('table', attrs={'class':'pagraph1'})
table = table[0]

trows = table.findAll('tr')
bbdata_ = []
bbdata = []
for trow in trows:
    bbdata_ = trow.findAll('td')
    bbdata = [ele.text.strip() for ele in bbdata_]

print(bbdata)
</code></pre>

<p>However, I can only extract the last row in the table, i.e.</p>

<pre><code>['Total*', '369', '1032+']
</code></pre>

<p>All of the data is included in the <code>trows</code>, so I must be forming my loop incorrectly, but I am not sure how.</p>

<p>Your problem is here:</p>

<pre><code>bbdata = [ele.text.strip() for ele in bbdata_]
</code></pre>

<p>You want to append to the list or extend it:</p>

<pre><code>bbdata.append([ele.text.strip() for ele in bbdata_])
</code></pre>

<p>You are overwriting bbdata each time through the loop which is why it ends up only with the final value.</p>

python beautifulsoup html-table