title: Python BeautifulSoup and Pandas extract table from list of urls and save all the tables into single dataframe or save as csv
body: <p>I am trying to extract tabular data from a list of urls and I want to save all the table into a single csv file.</p>
  <p>I am new and relatively beginner in python and from non-CS background, however I am very eager to learn the same.</p>
  <pre><code>import pandas as pd
  import urllib.request
  import bs4 as bs
  
  urls = ['A', 'B','C','D',...'Z']
  
  for url in urls:
      source = urllib.request.urlopen(url).read()
      soup = bs.BeautifulSoup(source,'lxml')
      table = soup.find('table', class_='tbldata14 bdrtpg')
      table_rows = table.find_all('tr')
  
  data = []
  for tr in table_rows:
      td = tr.find_all('td')
      row = [tr.text for tr in td]
      data.append(row)
  
  final_table = pd.DataFrame(data, columns=[&quot;ABC&quot;, &quot;XYZ&quot;,...])
  final_table.to_csv (r'F:\Projects\McData.csv', index = False, header=True)
  
  </code></pre>
  <p>What I Get from above code in newly created csv file is  -</p>
  <pre><code>ABC XYZ PQR MNL CYP ZXS
  1   2   3   4   5   6
  
  </code></pre>
  <p>My above code only gets table from <strong>last url- 'Z'</strong>, which, as I  have checked is actually the table from last url in list.</p>
  <p>What I am trying to achieve here is getting all tables from list of urls - i.e. A to Z into single csv file.</p>