title: Bytes to String or String to Bytes?
body: <p>I have read some of the examples here but I am such a novice I don't understand some of them and others don't seem to work(probably because I'm such a novice but...</p>
  
  <pre><code>import urllib.request
  import re
  Symbols = ['aapl', 'spy' , 'goog' , 'nflx']
  i = 0
  while i &lt; len(Symbols):
      Yahoo='http://finance.yahoo.com/q?s=' + Symbols[i]
      htmlfile = urllib.request.urlopen(Yahoo)
      htmltext = htmlfile.read()
      string = Symbols[i]
      symbol = string.encode('utf-8')
      pattern= re.compile(b'&lt;span id="yfs_l84_'+ symbol +'"&gt;(.+?)&lt;/span&gt;')
      price= re.findall(pattern, htmltext)
      print('The price of' + str(Symbols[i]) + ' is ' + str(price))
      i+=1
  </code></pre>
  
  <p>This doesn't work because in the <code>re.compile</code> statement I am trying to concatenate str and bytes.</p>
  
  <p>I need to convert the string to bytes so that I can later iterate over a list of symbols and scrape the latest stock price from yahoo finance.</p>
  
  <p>I have a feeling there is something wrong with my syntax there and the examples and python documentation has an argument for 'encoding' which I think is the 'utf-8' string but I don't really know.</p>
  
  <p>Can someone help me with this?</p>
  
  <p>Edit: I am using Bytes here because that is the only way it works, I get an error to change it to bytes if I don't (I am using 3.3).</p>
  
  <p>The error is this:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\Deaven And Teigan\Documents\Python Projects\YahooFinance.py", line 14, in &lt;module&gt;
      pattern= re.compile(b'&lt;span id="yfs_l84_'+ symbol +'"&gt;(.+?)&lt;/span&gt;')
  TypeError: can't concat bytes to str
  </code></pre>