title: python2.7 and beautiful soup 4 (bs4)
body: <p>I ran into another problem, I'm tied to using python2.7, can't use any newer, also I'm using beautiful soup 4 with python2.7</p>
  
  <p>Anyways my question is, how do I extract following data from all .. sections from a website's code?</p>
  
  <pre><code>&lt;tr id="id-gainers-adtoken-1h"&gt;
  &lt;td class="text-right"&gt;
  1
  &lt;/td&gt;
  &lt;td class="no-wrap currency-name"&gt;
  &lt;img src="https://files.coinmarketcap.com/static/img/coins/16x16/adtoken.png" class="currency-logo" alt="adToken"&gt;
  &lt;a href="/currencies/adtoken/"&gt;adToken&lt;/a&gt;
  &lt;/td&gt;
  
  &lt;td class="text-left"&gt;ADT&lt;/td&gt;
  
  &lt;td class="no-wrap text-right"&gt;
  &lt;a href="/currencies/adtoken/#markets" class="volume" data-usd="45657000.0" data-btc="4103.75"&gt;$45,657,000&lt;/a&gt;
  &lt;/td&gt;
  
  &lt;td class="no-wrap text-right"&gt;
  &lt;a href="/currencies/adtoken/#markets" class="price" data-usd="0.198131" data-btc="1.78084e-05"&gt;$0.198131&lt;/a&gt;
  &lt;/td&gt;
  
  &lt;td class="no-wrap percent-1h  positive_change  text-right" data-usd="36.36" data-btc="33.02"&gt;36.36%&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>I need following data:</p>
  
  <pre><code>"adtoken" and "1h" from first line
  &lt;tr id="id-gainers-adtoken-1h"&gt;
  
  36.36% from
  &lt;td class="no-wrap percent-1h  positive_change  text-right" data-usd="36.36" data-btc="33.02"&gt;36.36%&lt;/td&gt;
  </code></pre>
  
  <p>I'd like to collect all those values in a list of dictionaries, like so:</p>
  
  <pre><code>biggest_gainers = [
  { "name": "adtoken", "timeframe": "1h", "gain": "36.36%" },
  { "name": "spectre-dividend", "timeframe": "1h", "gain": "34.34%" } ]
  </code></pre>
  
  <p>my code so far is writing everything of the html code that contains "('tr')" to a file. From here I couldn't figure out how to continue, I've tried multiple split scenarios, deleting the indexes and also removing the last n character from the string with [:-3] after reading the file line by line.</p>
  
  <pre><code>from bs4 import BeautifulSoup as bs
  import urllib2
  from time import sleep
  
  url = urllib2.urlopen('https://coinmarketcap.com/gainers-losers/')
  soup = bs(url)
  
  
  print(soup)
  with open('somefile.txt', 'a') as f:
  
      for item in soup('tr'):
          f.write(str(item))
      f.close()
  </code></pre>
  
  <p>I believe my general approach to this is completely wrong, as I should not need to write it to a file first and then parse that file.</p>
  
  <p>Any ideas are much appreciated.</p>