title: Python BeautifulSoup, iterating through tags and attributes
body: <p>I would like to iterate through all the tag I have in certain section of the html page. I applied the BeautifulSoup, but I could live without it and just the Selenium library.
  Let's say I have the following html code:</p>
  
  <pre><code>&lt;table id="myBSTable"&gt;   
      &lt;tr&gt;
          &lt;th&gt;Column A1&lt;/th&gt;
          &lt;th&gt;Column B1&lt;/th&gt;
          &lt;th&gt;Column C1&lt;/th&gt;
          &lt;th&gt;Column D1&lt;/th&gt;
          &lt;th&gt;Column E1&lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td data="First Column Data"&gt;&lt;/td&gt;
          &lt;td data="Second Column Data"&gt;&lt;/td&gt;
          &lt;td title="Title of the First Row"&gt;Value of Row 1&lt;/td&gt;
          &lt;td&gt;Beautiful 1&lt;/td&gt;
          &lt;td&gt;Soup 1&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td data-g="Second Column Data"&gt;&lt;/td&gt;
          &lt;td title="Title of the Second Row"&gt;Value of Row 2&lt;/td&gt;
          &lt;td&gt;Selenium 1&lt;/td&gt;
          &lt;td&gt;Rocks 1&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td title="Title of the Third Row"&gt;Value of Row 3&lt;/td&gt;
          &lt;td&gt;Pyhon 1&lt;/td&gt;
          &lt;td&gt;Boulder 1&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;th&gt;Column A2&lt;/th&gt;
          &lt;th&gt;Column B2&lt;/th&gt;
          &lt;th&gt;Column C2&lt;/th&gt;
          &lt;th&gt;Column D2&lt;/th&gt;
          &lt;th&gt;Column E2&lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td data="First Column Data"&gt;&lt;/td&gt;
          &lt;td data="Second Column Data"&gt;&lt;/td&gt;
          &lt;td title="Title of the First Row"&gt;Value of Row 1&lt;/td&gt;
          &lt;td&gt;Beautiful 2&lt;/td&gt;
          &lt;td&gt;Soup 2&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td data-g="Second Column Data"&gt;&lt;/td&gt;
          &lt;td title="Title of the Second Row"&gt;Value of Row 2&lt;/td&gt;
          &lt;td&gt;Selenium 2&lt;/td&gt;
          &lt;td&gt;Rocks 2&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td title="Title of the Third Row"&gt;Value of Row 3 2&lt;/td&gt;
          &lt;td&gt;Pyhon 2&lt;/td&gt;
          &lt;td&gt;Boulder 2&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;  
  </code></pre>
  
  <p>I have this part working perfectly:</p>
  
  <pre><code>#Selenium libraries
  from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  from selenium.common.exceptions import NoSuchElementException
  
  #BeautifulSoup
  from bs4 import BeautifulSoup
  
  browser = webdriver.Firefox()
  browser.get('http://urltoget.com')   
  
  table = browser.find_element_by_id('myBSTable')
  bs_table = BeautifulSoup(table.get_attribute('innerHTML'), 'lxml')
  #So far so good
  rows = bs_table.findAll('tr')
  for tr in rows:
      #Here is where I need help
      #I want to iterate through all tags
      #but I don't know if is going to be a th or a td
      #At the same time I need to do something
      #if is a td or a th
  </code></pre>
  
  <p>And this is what I want to accomplish:</p>
  
  <pre><code>    #The following is a pseudo code
      for col in tr.tags:
          print col.name, col.value
          for attribute in col.attrs:
              print "    ", attribute.name, attribute.value
      #End pseudo code
  </code></pre>
  
  <p>Thanks,
  Arty</p>